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 framework to scrape Pastebin pastes and analyze them

pastepwn - Paste-Scraping Python Framework Pastebin is a very helpful tool to store or rather share ascii encoded data online. In the world of OSINT,

Rico 105 Dec 29, 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
A Python Oriented tool to Scrap WhatsApp Group Link using Google Dork it Scraps Whatsapp Group Links From Google Results And Gives Working Links.

WaGpScraper A Python Oriented tool to Scrap WhatsApp Group Link using Google Dork it Scraps Whatsapp Group Links From Google Results And Gives Working

Muhammed Rizad 27 Dec 18, 2022
Scraping news from Ucsal portal with Scrapy.

NewsScraping Esse é um projeto de raspagem das últimas noticias, de 2021, do portal da universidade Ucsal http://noosfero.ucsal.br/institucional Tecno

Crissiano Pires 0 Sep 30, 2021
Visual scraping for Scrapy

Portia Portia is a tool that allows you to visually scrape websites without any programming knowledge required. With Portia you can annotate a web pag

Scrapinghub 8.7k Jan 05, 2023
A Python web scraper to scrape latest posts from official Coinbase's Blog.

Coinbase Blog Scraper A Python web scraper to scrape latest posts from official Coinbase's Blog. IDEA It scrapes up latest blog posts from https://blo

Lucas Villela 3 Feb 18, 2022
Consulta de CPF e CNPJ na Receita Federal com Web-Scraping

Repositório contendo scripts Python que realizam a consulta de CPF e CNPJ diretamente no site da Receita Federal.

Josué Campos 5 Nov 29, 2021
Web-Scraping using Selenium Master

Web-Scraping using Selenium What is the need of Selenium? Some websites don't like to be scrapped and in that case you need to disguise your webscrapi

Md Rashidul Islam 1 Oct 26, 2021
Examine.com supplement research scraper!

ExamineScraper Examine.com supplement research scraper! Why I want to be able to search pages for a specific term. For example, I want to be able to s

Tyler 15 Dec 06, 2022
WebScraper - A script that prints out a list of all EXTERNAL references in the HTML response to an HTTP/S request

Project A: WebScraper A script that prints out a list of all EXTERNAL references

2 Apr 26, 2022
This app will let you continuously scrape certain parts of LeasePlan and extract data of cars becoming available for lease.

LeasePlan - Scraper This app will let you continuously scrape certain parts of LeasePlan and extract data of cars becoming available for lease. It has

Rodney 4 Nov 18, 2022
This Spider/Bot is developed using Python and based on Scrapy Framework to Fetch some items information from Amazon

- Hello, This Project Contains Amazon Web-bot. - I've developed this bot for fething some items information on Amazon. - Scrapy Framework in Python is

Khaled Tofailieh 4 Feb 13, 2022
Collection of code files to scrap different kinds of websites.

STW-Collection Scrap The Web Collection; blog posts. This repo contains Scrapy sample code to scrap the following kind of websites: Do you want to lea

Tapasweni Pathak 15 Jun 08, 2022
A Python module to bypass Cloudflare's anti-bot page.

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

VeNoMouS 2.6k Dec 31, 2022
Automated Linkedin bot that will improve your visibility and increase your network.

LinkedinSpider LinkedinSpider is a small project using browser automating to increase your visibility and network of connections on Linkedin. DISCLAIM

Frederik 2 Nov 26, 2021
crypto currency scraping

SCRYPTO What ? Crypto currencies scraping (At the moment, only bitcoin and ethereum crypto currencies are supported) How ? A python script is running

15 Sep 01, 2022
A spider for Universal Online Judge(UOJ) system, converting problem pages to PDFs.

Universal Online Judge Spider Introduction This is a spider for Universal Online Judge (UOJ) system (https://uoj.ac/). It also works for all other Onl

TriNitroTofu 1 Dec 07, 2021
Simple proxy scraper made by using ProxyScrape's api.

What is Moon? Moon is a lightweight and fast proxy scraper made by using ProxyScrape's api. What can i do with this? You can use proxies for varietys

1 Jul 04, 2022
Webservice wrapper for hhursev/recipe-scrapers (python library to scrape recipes from websites)

recipe-scrapers-webservice This is a wrapper for hhursev/recipe-scrapers which provides the api as a webservice, to be consumed as a microservice by o

1 Jul 09, 2022
Binance harvester - A Python 3 script to harvest data from the Binance socket stream and calculate popular TA indicators and produce lists of top trending coins

Binance harvester - A Python 3 script to harvest data from the Binance socket stream and calculate popular TA indicators and produce lists of top trending coins

68 Oct 08, 2022