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
Screenhook is a script that captures an image of a web page and send it to a discord webhook.

screenshot from the web for discord webhooks screenhook is a script that captures an image of a web page and send it to a discord webhook.

Toast Energy 3 Jun 04, 2022
🕷 Phone Crawler with multi-thread functionality

Phone Crawler: Phone Crawler with multi-thread functionality Disclaimer: I'm not responsible for any illegal/misuse actions, this program was made for

Kmuv1t 3 Feb 10, 2022
New World Market Scraper

Bean Seller A New Worlds market scraper. Deployment This must be installed on Windows as it uses the Windows api to do its stuff Install Prerequisites

4 Sep 21, 2022
Telegram Group Scrapper

this programe is make your work so much easy on telegrame. do you want to send messages on everyone to your group or others group. use this script it will do your work automatically with one click. a

HackArrOw 3 Dec 03, 2022
Web3 Pancakeswap Sniper bot written in python3

Pancakeswap_BSC_Sniper_Bot Web3 Pancakeswap Sniper bot written in python3, Please note the license conditions! The first Binance Smart Chain sniper bo

Treading-Tigers 295 Dec 31, 2022
DaProfiler allows you to get emails, social medias, adresses, works and more on your target using web scraping and google dorking techniques

DaProfiler allows you to get emails, social medias, adresses, works and more on your target using web scraping and google dorking techniques, based in France Only. The particularity of this program i

Dalunacrobate 347 Jan 07, 2023
Basic-html-scraper - A complete how to of web scraping with Python for beginners

basic-html-scraper Code from YT Video This video includes a complete how to of w

John 12 Oct 22, 2022
Dictionary - Application focused on word search through web scraping

Dictionary - Application focused on word search through web scraping, in addition to other functions such as dictation, spell and conjugation of syllables.

Juan Manuel 2 May 09, 2022
Python script to check if there is any differences in responses of an application when the request comes from a search engine's crawler.

crawlersuseragents This Python script can be used to check if there is any differences in responses of an application when the request comes from a se

Podalirius 13 Dec 27, 2022
Scrape Twitter for Tweets

Backers Thank you to all our backers! 🙏 [Become a backer] Sponsors Support this project by becoming a sponsor. Your logo will show up here with a lin

Ahmet Taspinar 2.2k Jan 05, 2023
An helper library to scrape data from Instagram effortlessly, using the Influencer Hunters APIs.

Instagram Scraper An utility library to scrape data from Instagram hassle-free Go to the website » View Demo · Report Bug · Request Feature About The

2 Jul 06, 2022
News, full-text, and article metadata extraction in Python 3. Advanced docs:

Newspaper3k: Article scraping & curation Inspired by requests for its simplicity and powered by lxml for its speed: "Newspaper is an amazing python li

Lucas Ou-Yang 12.3k Jan 07, 2023
A web scraper that exports your entire WhatsApp chat history.

WhatSoup 🍲 A web scraper that exports your entire WhatsApp chat history. Table of Contents Overview Demo Prerequisites Instructions Frequen

Eddy Harrington 87 Jan 06, 2023
热搜榜-python爬虫+正则re+beautifulsoup+xpath

仓库简介 微博热搜榜, 参数wb 百度热搜榜, 参数bd 360热点榜, 参数360 csdn热榜接口, 下方查看 其他热搜待加入 如何使用? 注册vercel fork到你的仓库, 右上角 点击这里完成部署(一键部署) 请求参数 vercel配置好的地址+api?tit=+参数(仓库简介有参数信息

Harry 3 Jul 08, 2022
Pro Football Reference Game Data Webscraper

Pro Football Reference Game Data Webscraper Code Copyright Yeetzsche This is a simple Pro Football Reference Webscraper that can either collect all ga

6 Dec 21, 2022
Linkedin webscraping - Linkedin web scraping with python

linkedin_webscraping This is the first step of a full project called "LinkedIn J

Pedro Dib 4 Apr 24, 2022
Scrapes proxies and saves them to a text file

Proxy Scraper Scrapes proxies from https://proxyscrape.com and saves them to a file. Also has a customizable theme system Made by nell and Lamp

nell 2 Dec 22, 2021
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
Dailyiptvlist.com Scraper With Python

Dailyiptvlist.com scraper Info Made in python Linux only script Script requires to have wget installed Running script Clone repository with: git clone

1 Oct 16, 2021
一款利用Python来自动获取QQ音乐上某个歌手所有歌曲歌词的爬虫软件

QQ音乐歌词爬虫 一款利用Python来自动获取QQ音乐上某个歌手所有歌曲歌词的爬虫软件,默认去除了所有演唱会(Live)版本的歌曲。 使用方法 直接运行python run.py即可,然后输入你想获取的歌手名字,然后静静等待片刻。 output目录下保存生成的歌词和歌名文件。以周杰伦为例,会生成两

Yang Wei 11 Jul 27, 2022