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
Using Python and Pushshift.io to Track stocks on the WallStreetBets subreddit

wallstreetbets-tracker Using Python and Pushshift.io to Track stocks on the WallStreetBets subreddit.

91 Dec 08, 2022
优化版本的京东茅台抢购神器

优化版本的京东茅台抢购神器

1.8k Mar 18, 2022
An Automated udemy coupons scraper which scrapes coupons and autopost the result in blogspot post

Autoscraper-n-blogger An Automated udemy coupons scraper which scrapes coupons and autopost the result in blogspot post and notifies via Telegram bot

GOKUL A.P 13 Dec 21, 2022
A Python package that scrapes Google News article data while remaining undetected by Google.

A Python package that scrapes Google News article data while remaining undetected by Google. Our scraper can scrape page data up until the last page and never trigger a CAPTCHA (download stats: https

Geminid Systems, Inc 6 Aug 10, 2022
Python scrapper scrapping torrent website and download new movies Automatically.

torrent-scrapper Python scrapper scrapping torrent website and download new movies Automatically. If you like it Put a ⭐ on this repo 😇 Run this git

Fazil vk 1 Jan 08, 2022
A simple Discord scraper for discord bots

A simple Discord scraper for discord bots. That includes sending an guild members ids to an file, Mass inviter for joining servers your bot is in and Fetching all the servers of the bot (w/MemberCoun

3zg 1 Jan 06, 2022
Libextract: extract data from websites

Libextract is a statistics-enabled data extraction library that works on HTML and XML documents and written in Python

499 Dec 09, 2022
Simple python tool for the purpose of swapping latinic letters with cirilic ones and vice versa in txt, docx and pdf files in Serbian language

Alpha Swap English This is a simple python tool for the purpose of swapping latinic letters with cirylic ones and vice versa, in txt, docx and pdf fil

Aleksandar Damnjanovic 3 May 31, 2022
This program will help you to properly scrape all data from a specific website

This program will help you to properly scrape all data from a specific website

MD. MINHAZ 0 May 15, 2022
Bulk download tool for the MyMedia platform

MyMedia Bulk Content Downloader This is a bulk download tool for the MyMedia platform. USE ONLY WHERE ALLOWED BY THE COPYRIGHT OWNER. NOT AFFILIATED W

Ege Feyzioglu 3 Oct 14, 2022
Meme-videos - Scrapes memes and turn them into a video compilations

Meme Videos Scrapes memes from reddit using praw and request and then converts t

Partho 12 Oct 28, 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
A crawler of doubamovie

豆瓣电影 A crawler of doubamovie 一个小小的入门级scrapy框架的应用,选取豆瓣电影对排行榜前1000的电影数据进行爬取。 spider.py start_requests方法为scrapy的方法,我们对它进行重写。 def start_requests(self):

Cats without dried fish 1 Oct 05, 2021
京东茅台抢购

截止 2021/2/1 日,该项目已无法使用! 京东:约满即止,仅限京东实名认证用户APP端抢购,2月1日10:00开始预约,2月1日12:00开始抢购(京东APP需升级至8.5.6版本及以上) 写在前面 本项目来自 huanghyw - jd_seckill,作者的项目地址我找不到了,找到了再贴上

abee 73 Dec 03, 2022
API which uses discord to scrape NameMC searches/droptime/dropping status of minecraft names

NameMC Scrape API This is an api to scrape NameMC using message previews generated by discord. NameMC makes it a pain to scrape their website, but som

Twilak 2 Dec 22, 2021
淘宝茅台抢购最新优化版本,淘宝茅台秒杀,优化了茅台抢购线程队列

淘宝茅台抢购最新优化版本,淘宝茅台秒杀,优化了茅台抢购线程队列

MaoTai 118 Dec 16, 2022
Scrapes Every Email Address of Every Society in Every University

society-email-scrape Site Live at https://kcsoc.github.io/society-email-scrape/ How to automatically generate new data Go to unis.yml Add your uni Cre

Krishna Consciousness Society 18 Dec 14, 2022
Instagram_scrapper - This project allow you to scrape the list of followers, following or both from a public Instagram account, and create a csv or excel file easily.

Instagram_scrapper This project allow you to scrape the list of followers, following or both from a public Instagram account, and create a csv or exce

Lakhdar Belkharroubi 5 Oct 17, 2022
Crawler job that scrapes comments from social media posts and saves them in a S3 bucket.

Toxicity comments crawler Crawler job that scrapes comments from social media posts and saves them in a S3 bucket. Twitter Tweets and replies are scra

Douglas Trajano 2 Jan 24, 2022
A web service for scanning media hosted by a Matrix media repository

Matrix Content Scanner A web service for scanning media hosted by a Matrix media repository Installation TODO Development In a virtual environment wit

Brendan Abolivier 5 Dec 01, 2022