FesonX / finvest-spider

Finance and Investment Info Spider Collections - 投融资信息爬虫集合

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

finvest-spider

Finance and Investment Info Spider Collections - 投融资信息爬取集合

取Finance和Investment的前几个字母组成项目名

反爬策略

随机用户代理

此功能依赖于 fake_useragent 若出现下面的错误, 请尝试卸载该库重新安装

fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

延迟下载

settings.py 中修改下面的配置项启用延迟下载或者在爬虫的发起连接处使用 time.sleep(secs) 语句来延迟下载

# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 10

IP 池

默认不启用,使用前请移步 middleware/ipProxy.py 爬取可用 IP,然后再运行爬虫(需要自行配置 MySQL). 启用方式: 将 settings.py 中的 RandomIpMiddleware 取消注释即可.

# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
   'middleware.customUserAgent.RandomUserAgent': 543,
   # 'finvest.middlewares.RandomIpMiddleware': 543,
}

已接入爬虫的网站

投中网

Spider名称: trjcn 行业: 综合

投融界

Spider名称: cvnews 行业: 综合

36Kr

Spider名称: 36kr 行业: 综合

动脉网

Spider名称: vcbeat 行业: 医疗

芥末堆

Spider名称: jiemodui 行业: 教育

GAMELOOK

Spider名称: gamelook 行业: 游戏

爬虫分析过程

JS动态加载以及JavaScript void(0)的爬虫解决方案

安装依赖软件

  1. 安装MongoDB 注意:以Deepin为例,如果使用Ubuntu的安装方法报错--keyserver receive failed: No dirmngr,请先键入下面命令再使用上方链接的教程 sudo apt-get install software-properties-common dirmngr

如果安装完成后遇到 Failed to start mongod.service: Unit not found 请参考文章

  1. 安装Python
# For Ubuntu/Deepin etc.
apt-get install python3
  1. 安装库依赖 有关虚拟环境内容, 自行 Google Virtualenv pip install -r requirements.txt

常用的爬虫命令

  1. 爬取并输出csv文件 本项目默认输出 csv 文件, 关于输出的 pipeline 请参考 pipeline.py 中的相关类
scrapy crawl [spider_name] -o [doc_name].csv
  1. 爬取N页停止
scrapy crawl [spider_name] -s CLOSESPIDER_PAGECOUNT=[N]
  1. 爬取N项停止
scrapy crawl [spider_name] -s CLOSESPIDER_ITEMCOUNT=[N]
  1. 超时停止
scrapy crawl [spider_name] -s CLOSESPIDER_TIMEOUT=[N]

数据示例

请移步 data 文件夹. 仅供学习用途, 请勿商用.

LICENSE

MIT

About

Finance and Investment Info Spider Collections - 投融资信息爬虫集合

License:MIT License


Languages

Language:Python 99.8%Language:Shell 0.2%