A distributed crawler for weibo, building with celery and requests.

Overview

codecov GitHub issues

项目亮点

  • 功能全面:包括了用户信息抓取指定关键字搜索结果增量抓取指定用户主页所有原创微博抓取评论抓取转发关系抓取
  • 数据全面:PC端展现的数据量比移动端更加丰富。并且相比于其它同类项目对微博的简单分析,本项目做了大量细致的工作, 比如不同domain不同用户的解析策略、不同domain不同用户的主页分析策略等
  • 稳定!项目可以长期稳定运行
    • 为了保证程序能长期稳定运行,数据所有的网络请求都是通过抓包手动分析的,未用任何自动化工具,包括模拟登陆! 从另一个方面来说,抓取速度也是比较有保证的
    • 通过合理的阈值设定,账号可以保证安全。但是不推荐用户使用自己的常用账号
    • 即使账号不可用或者登陆失败,项目都对其做了处理(智能冻结账号,出错重试等),以保证每次请求都是有效的,并及时把错误反馈给用户
    • 通过大量的异常检测和处理,几乎捕获了所有的解析和抓取异常。编写了大量的解析代码来获取足够全面的信息
  • 复用性和扩展性好。项目很多地方都有详细的代码注释,方便阅读。即使本项目不能完全满足你对微博数据采集和分析的需求,你完全可以在该项目的基础上 做二次开发,项目已经在微博数据采集和模版解析上做了大量工作。
  • 该项目会长期更新,目前已经迭代一年有余了。
  • 丰富文档支持:点击wiki查看所有文档。如果文档仍然不能解 决你的问题,欢迎提issue,维护者看到后都会积极回答。

快速开始 :octocat:

1.阅读项目环境配置以配置项目所需的环境。

2.到release页面下载稳定版本的应用程序

3.解压你所下载的程序,并且cd到它的目录

4.快速安装所需依赖,如果你想使用虚拟环境管理依赖,那么使用source env.sh即可,如果你想使用系统的Python环境,那么使用pip3 install -r requirements.txt安装所有依赖

5.使用编辑器编辑配置文件spider.yml,设置MySQL、Redis连接信息、云打码(需要进行注册并充值)登录信息和邮箱报警信息。另外也可以对抓取间隔等进行配置,具体请阅读相关注释。

6.先通过手动创建一个名为weibo的数据库,然后使用python config/create_all.py来创建爬虫所需要的表,如果是v1.7.2及之前的版本,输入python create_all.py即可。

7.(可选,v1.7.3新增)如果你想通过Web UI来进行爬虫关键词等信息的配置,那么还需要修改admin/weibo_admin/settings.pyDATABSES一栏的数据库连接信息。 然后在项目根目录下运行

python admin/manage.py makemigrations
python admin/manage.py migrate
python admin/manage.py createsuperuser

以生成django admin所需要的一些数据表,在执行python admin/manage.py createsuperuser的时候,会让你输入django后台的超级管理员用户名、邮箱和密码,比如我依次输入为test[email protected]weibospider2017,然后便成功创建了超级管理员。

8.我们在爬虫程序启动之前,需要预插入微博账号和密码以及一些种子数据。比如你想抓取一个用户,那么就需要在seed_ids表中插入他的uiduid可以通过打开该用户主页,点击查看页面源代码搜索oid获取到。如果你想通过通过微博的搜索接口搜索一个关键词,那么需要在keywords表中插入你想搜索的关键词。如果你完成了步骤7,那么可以通过Web UI来进行配置。通过运行

python admin/manage.py runserver 0.0.0.0:8000

来启动爬虫配置后台。然后再在你的浏览器输入http://127.0.0.1:8000/admin来访问爬虫配置程序。在登录界面输入刚才创建的用户名test和密码weibospider2017即可,然后在微博配置一栏中进行配置。注意,django自带的web server无法达到生产级别的稳定性,如果需要 在生产环境中使用,建议使用gunicorn或者uwsgi作为web server,并且使用supervisor作为进程管理器。

9.配置完成后,通过

celery -A tasks.workers -Q login_queue,user_crawler,fans_followers,search_crawler,home_crawler worker -l info -c 1

启动worker。注意这里-Q表示在本机上可以接收哪些任务执行,详细请阅读weibospider中所有任务及其说明-c表示并发数,-l表示日志等级。

上述命令可以在多台机器上执行,以达到分布式抓取的目的。我们需要做的仅仅是在别的机器上装好项目所需依赖(通过source env.sh或者pip3 install -r requirements.txt),是不是很简单?

10.到这个时候,我们已经做好所有准备了。现在我们需要发送任务给worker。有两种方式:1)通过执行python first_task_execution/login_first.py来进行登录,其他任务发送操作也类似。2)由于我们采用定时的机制来应对微博Cookie24小时失效的问题和达到不间断抓取的目的,那么我们可以在任何一台节点执行

celery beat -A tasks.workers -l info

以启动一个celery beater,它会定时将任务发送给Celery Worker进行执行,注意beater只能有一个,否则任务可能重复执行。定时设置在tasks/workers.py这个文件。

到这里所有配置已经结束了,如果大家在上述过程中遇到了问题,请耐心浏览项目所有文档,实在还是不懂或者使用过程中有任何问题可以提issue。

捐赠作者 👍

如果项目对你有用或者对你有启发,不妨通过微信或者支付宝进行小额捐赠,以支持该项目的持续维护和发展。

  • 通过微信捐赠作者

  • 通过支付宝捐赠作者

重要声明 📢

该项目开发的初衷是为了对部分信息进行监控,并且获取一些自然语言处理所需的语料,在数据抓取的时候对爬虫访问频率进行了较为严格的控制。 后来在技术和兴趣的驱动下,才慢慢扩展了分布式和对微博反爬虫策略的探究。

所以作者希望用户能合理使用该项目(通过配置文件控制访问频率),本着够用就行的原则,不要做竭泽而渔 的事情,对微博系统的正常运行和维护造成较大的困扰。

其他

项目使用常见问题

项目补充说明

项目进程

致谢 ❤️

  • 感谢大神Askcelery分布式任务调度框架和大神kennethreitzrequests
  • 感谢为项目贡献源码的朋友,点击查看贡献者列表
  • 感谢所有捐赠本项目的朋友,点击查看捐赠者列表
  • 感谢star支持的网友和在使用过程中提issue或者给出宝贵建议的朋友
Owner
SpiderClub
A group interested in web crawler.
SpiderClub
此脚本为 python 脚本,实现原理为利用 selenium 定位相关元素,再配合点击事件完成浏览器的自动化.

此脚本为 python 脚本,实现原理为利用 selenium 定位相关元素,再配合点击事件完成浏览器的自动化.

N0el4kLs 5 Nov 19, 2021
Minimal set of tools to conduct stealthy scraping.

Stealthy Scraping Tools Do not use puppeteer and playwright for scraping. Explanation. We only use the CDP to obtain the page source and to get the ab

Nikolai Tschacher 88 Jan 04, 2023
Audio media crawler for lbry.

Audio media crawler for lbry. Requirements Python 3.8 Poetry 1.1.7 Elasticsearch 7.14.0 Lbry-sdk 0.99.0 Development This project uses poetry as a depe

Hound.fm 4 Dec 03, 2022
京东秒杀商品抢购Python脚本

Jd_Seckill 非常感谢原作者 https://github.com/zhou-xiaojun/jd_mask 提供的代码 也非常感谢 https://github.com/wlwwu/jd_maotai 进行的优化 主要功能 登陆京东商城(www.jd.com) cookies登录 (需要自

Andy Zou 1.5k Jan 03, 2023
A Python module to bypass Cloudflare's anti-bot page.

cloudflare-scrape A simple Python module to bypass Cloudflare's anti-bot page (also known as "I'm Under Attack Mode", or IUAM), implemented with Reque

3k Jan 04, 2023
Simply scrape / download all the media from an fansly account.

Simply scrape / download all the media from an fansly account. Providing updates as long as its continuously gaining popularity, so hit the ⭐ button!

Mika C. 334 Jan 01, 2023
Scrapy uses Request and Response objects for crawling web sites.

Requests and Responses¶ Scrapy uses Request and Response objects for crawling web sites. Typically, Request objects are generated in the spiders and p

Md Rashidul Islam 1 Nov 03, 2021
This is python to scrape overview and reviews of companies from Glassdoor.

Data Scraping for Glassdoor This is python to scrape overview and reviews of companies from Glassdoor. Please use it carefully and follow the Terms of

Houping 5 Jun 23, 2022
Web-scraping - A bot using Python with BeautifulSoup that scraps IRS website by form number and returns the results as json

Web-scraping - A bot using Python with BeautifulSoup that scraps IRS website (prior form publication) by form number and returns the results as json. It provides the option to download pdfs over a ra

1 Jan 04, 2022
基于Github Action的定时HITsz疫情上报脚本,开箱即用

HITsz Daily Report 基于 GitHub Actions 的「HITsz 疫情系统」访问入口 定时自动上报脚本,开箱即用。 感谢 @JellyBeanXiewh 提供原始脚本和 idea。 感谢 @bugstop 对脚本进行重构并新增 Easy Connect 校内代理访问。

Ter 56 Nov 27, 2022
Scrapes all articles and their headlines from theonion.com

The Onion Article Scraper Scrapes all articles and their headlines from the satirical news website https://www.theonion.com Also see Clickhole Article

0 Nov 17, 2021
京东茅台抢购 2021年4月最新版

Jd_Seckill 特别声明: 本仓库发布的jd_seckill项目中涉及的任何脚本,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。 本项目内所有资源文件,禁止任何公众号、自媒体进行任何形式的转载、发布。 huanghyw 对任何脚本问题概不

45 Dec 14, 2022
Quick Project made to help scrape Lexile and Atos(AR) levels from ISBN

Lexile-Atos-Scraper Quick Project made to help scrape Lexile and Atos(AR) levels from ISBN You will need to install the chrome webdriver if you have n

1 Feb 11, 2022
Danbooru scraper with python

Danbooru Version: 0.0.1 License under: MIT License Dependencies Python: = 3.9.7 beautifulsoup4 cloudscraper Example of use Danbooru from danbooru imp

Sugarbell 2 Oct 27, 2022
robobrowser - A simple, Pythonic library for browsing the web without a standalone web browser.

RoboBrowser: Your friendly neighborhood web scraper Homepage: http://robobrowser.readthedocs.org/ RoboBrowser is a simple, Pythonic library for browsi

Joshua Carp 3.7k Dec 27, 2022
Goblyn is a Python tool focused to enumeration and capture of website files metadata.

Goblyn Metadata Enumeration What's Goblyn? Goblyn is a tool focused to enumeration and capture of website files metadata. How it works? Goblyn will se

Gustavo 46 Nov 22, 2022
Proxy scraper. Format: IP | PORT | COUNTRY | TYPE

proxy scraper 🔎 Installation: git clone https://github.com/ebankoff/proxy_scraper Required pip libraries (pip install library name): lxml beautifulso

Eban'ko 19 Dec 07, 2022
This is a simple website crawler which asks for a website link from the user to crawl and find specific data from the given website address.

This is a simple website crawler which asks for a website link from the user to crawl and find specific data from the given website address.

Faisal Ahmed 1 Jan 10, 2022
Pyrics is a tool to scrape lyrics, get rhymes, generate relevant lyrics with rhymes.

Pyrics Pyrics is a tool to scrape lyrics, get rhymes, generate relevant lyrics with rhymes. ./test/run.py provides the full function in terminal cmd

MisterDK 1 Feb 12, 2022
Scrapy-soccer-games - Scraping information about soccer games from a few websites

scrapy-soccer-games Esse projeto tem por finalidade pegar informação de tabela d

Caio Alves 2 Jul 20, 2022