# scraper **Repository Path**: gitdogcat_admin/scraper ## Basic Information - **Project Name**: scraper - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-07 - **Last Updated**: 2026-08-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Scraper — 轻量网页抓取工具 一个不依赖容器的 Python 网页抓取工具集,做好浏览器伪装,输出干净 Markdown 正文。 ## 项目结构 ``` scraper/ ├── stealth.py 伪装会话模块(可被所有爬虫脚本复用) ├── scraper.py 通用网页抓取(给 URL → 提取正文) ├── cninfo_spider.py 巨潮网公告爬虫(沪深股东大会决议公告) ├── requirements.txt 依赖清单 └── README.md ``` ### stealth.py — 伪装会话模块 核心模块,提供 `ScraperSession` 类,所有爬虫脚本共用: - TLS 指纹匹配(curl_cffi impersonate) - 6 个浏览器画像(Chrome/Firefox/Safari × Linux/Windows/macOS) - 完整浏览器请求头(Sec-Ch-Ua / Sec-Fetch-* / Accept-Encoding…) - Session cookies 持久化(真人行为) - Referer 链(第二次请求自动带来源页) - Sec-Fetch-Site 动态切换(同站 same-origin / 跨站 cross-site) - 随机延迟(2-8 秒抖动) - 一个会话只用一个画像(不会中途换浏览器) - 支持 GET / POST / 代理 ```python from stealth import ScraperSession session = ScraperSession(verbose=True) html = session.fetch("https://example.com") # GET,返回文本 resp = session.get("https://example.com") # GET,返回 Response resp = session.post("https://api.com", data={"k": "v"}) # POST,返回 Response ``` ### scraper.py — 通用网页抓取 给定 URL,输出干净正文(Markdown / Text / HTML / XML)。 ```bash # 抓单个页面 python3 scraper.py https://example.com/article # 输出纯文本 python3 scraper.py https://example.com/article --format text # 写入文件 python3 scraper.py https://example.com/article -o result.md # 带页面元信息和链接 python3 scraper.py https://example.com/article --metadata --links # 指定浏览器画像 python3 scraper.py https://example.com --profile chrome-windows # 走代理 python3 scraper.py https://example.com --proxy socks5://127.0.0.1:1080 # 抓整站(从 sitemap 发现页面) python3 scraper.py https://example.com --sitemap --max-pages 100 -o site.md # 查看所有画像 python3 scraper.py --list-profiles ``` ### cninfo_spider.py — 巨潮网公告爬虫 抓取沪深股东大会决议公告,存 CSV。 ```bash # 抓最近1天(默认) python3 cninfo_spider.py # 抓最近3天 python3 cninfo_spider.py --days 3 # 指定画像 + 走代理 python3 cninfo_spider.py --profile chrome-windows --proxy socks5://127.0.0.1:1080 # 调试模式 python3 cninfo_spider.py -v ``` 输出文件:`announcements/announcements_YYYYMMDD.csv` 字段:id, announcementId, announcementTitle, secCode, secName, announcementTime, pdfUrl, fileType, shortTitle, storageTime ## 安装 ```bash pip install -r requirements.txt ``` > curl_cffi 是可选但强烈推荐——没有它 TLS 指纹会是 Python 而非浏览器。 ## 浏览器画像 | 画像 | TLS 指纹 | 平台 | |------|----------|------| | chrome-linux | chrome | Linux | | chrome-windows | chrome | Windows | | chrome-macos | chrome | macOS | | firefox-linux | firefox | Linux | | firefox-windows | firefox | Windows | | safari-macos | safari | macOS | 不指定 `--profile` 时随机选一个。一个会话只用一个画像,不会中途切换。 ## 伪装原理 | 层面 | 实现 | |------|------| | TLS 指纹 | curl_cffi impersonate 匹配浏览器 | | User-Agent | 与 TLS 指纹一致 | | Sec-Ch-Ua | Chrome 画像带 Client Hints | | Sec-Fetch-* | 动态切换 same-origin / cross-site;POST 时自动切 cors/empty | | Referer | 第二次请求自动带来源页 | | Cookies | Session 全程保持 | | 延迟 | 2-8 秒随机抖动 | | POST 头 | 自动设 Content-Type / X-Requested-With,Sec-Fetch-Dest 切 empty | ## License MIT