Skip to main content

DiiDu爬虫-python版本

尽力做到了对操作, 使用的还原.

使用

config的配置

  • 要求
config = {
    'base_url': '...',  <-- 爬虫入口
    'content': {  <-- 用于划分主要区域
        'spilt_func': 'extract_content',
        'spilt_args': [
            '<div class="box1">', 
            '<div id="div_vote_id"></div>'
        ]
    },
    'value':{
        '标题'<--字段名: {
            'spilt_func': 'extract_content', <-- 使用的函数(暂时只有extract_content)
            'spilt_args': [
                '<p class="bt">',  <-- 参数
                '</p>'
            ]
        },
        ...可以自行添加其他字段名
    },
    'Next':{  <-- 下一页的配置
        'css':'a.Next',
        'name':'下页'  <-- 如果a.Next不唯一, 则可以根据name来筛选
    },
    'son':{
        'css': '.p2_right>ul>li>a'  <-- 子标签的css选择器
    }
}
  • 示例
config = {
    'base_url': '...',
    'content': {
        'spilt_func': 'extract_content',
        'spilt_args': [
            '<div class="box1">', 
            '<div id="div_vote_id"></div>'
        ]
    },
    'value':{
        '标题': {
        'spilt_func': 'extract_content',
        'spilt_args': [
            '<p class="bt">',
            '</p>'
        ]
        },
        '发布时间': {
        'spilt_func': 'extract_content',
        'spilt_args': [
            '<p>发布时间:',
            '</p>'
        ]
        },
        '正文内容': {
        'spilt_func': 'extract_content',
        'spilt_args': [
            '<div class="v_news_content">',
            '</div>'
        ]
        }
    },
    'Next':{
        'css':'a.Next',
        'name':'下页'
    },
    'son':{
        'css': '.p2_right>ul>li>a'
    }
}

main.py

from spider_kel import *
from competition_config import config
name = ''
import csv

if __name__ == "__main__":
    result = Spider(config)  # 结果为csv格式 [[title1, ..], [value1, ..], ..]
    
    # 保存结果到文件
    encoding = get_encoding(config['base_url'])  # 防止出现文件乱码的情况!
    with open(f'竞赛信息.csv', 'w', encoding=encoding, newline='') as f:
        writer = csv.writer(f)
        writer.writerows(result)

更新与优化

  • 如果你想要更多功能, 或者遇到问题:
    可以加qq: 2075389406 或 2075389406@qq.com 进行交流

Metadata

Release files for zut-spider 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for zut-spider 0.1.3
File Interpreter ABI Platform
zut_spider-0.1.3-py3-none-any.whl Python 3 none any Details

Release files / zut_spider-0.1.3-py3-none-any.whl

Download URL zut_spider-0.1.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a6219f0812e6170c10539265166b1004ac16a022643fd54dbc9ba2d88fa9d8c
BLAKE2b-256 checksum
How to use checksums
077131e2f0a13b41eeea8422d3467ac67aeb55eeb69d5a7facd68fc5757b653a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Security for zut-spider 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page