Weibo Spider
modelthis | identifier in transformers | description | download url |
---|---|---|---|
nghuyong/ernie-1.0nghuyong/ernie- | nghuyong/ernie-1.0 | Layer:12, Hidden:768, Heads:12 | http://pan.nghuyong.top/#/s/y7Uz |
ernie-2.0-en (English) | nghuyong/ernie-2.0-en | Layer:12, Hidden:768, Heads:12 | http://pan.nghuyong.top/#/s/BXh9 |
ernie-2.0-large-en (English) | nghuyong/ernie-2.0-large-en | Layer:24, Hidden:1024, Heads16 | http://pan.nghuyong.top/#/s/DxiK |
ernie-tiny (English) | nghuyong/ernie-tiny | Layer:3, Hdden:1024, Heads:16 | http://pan.nghuyong.top/#/s/AOf3 |
表头 | 表头 |
---|---|
单元格 | 单元格单元格单元格单元格单元格单元格单元格单元格单元格单元格 |
单元格 | 单元格 |
本程序可以连续爬取一个或多个新浪微博用户(如胡歌、迪丽热巴、郭碧婷)的数据,并将结果信息写入文件或数据库。写入信息几乎包括用户微博的所有数据,包括用户信息和微博信息两大类。因为内容太多,这里不再赘述,详细内容见获取到的字段。如果只需要用户信息,可以通过设置实现只爬取微博用户信息的功能。本程序需设置cookie来获取微博访问权限,后面会讲解如何获取cookie。如果不想设置cookie,可以使用免cookie版,二者功能类似。
具体的写入文件类型如下:
- 写入txt文件(默认)
微博信息
- 微博id:微博唯一标志
- 微博内容:微博正文
使用说明
0.版本
本程序有两个版本,你现在看到的是python3版,另一个是python2版,python2版位于python2分支。目前主力开发python3版,包括新功能开发和bug修复;python2版仅支持bug修复。推荐python3用户使用当前版本,推荐python2用户使用python2版,本使用说明是python3版的使用说明。
1.安装程序
本程序提供两种安装方式,一种是源码安装,另一种是pip安装,二者功能完全相同。如果你需要修改源码,建议使用第一种方式,否则选哪种安装方式都可以。
源码安装
$ git clone https://github.com/dataabc/weiboSpider.git
$ cd weiboSpider
$ pip install -r requirements.txt
pip安装
$ python3 -m pip install weibo-spider
使用正则表达式
正则表达式相关知识
在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要,正则表达式就是用于描述这些规则的工具,换句话说正则表达式是一种工具,它定义了字符串的匹配模式(如何检查一个字符串是否有跟某种模式匹配的部分或者从一个字符串中将与模式匹配的部分提取出来或者替换掉)。如果你在Windows操作系统中使用过文件查找并且在指定文件名时使用过通配符(*和?),那么正则表达式也是与之类似的用来进行文本匹配的工具,只不过比起通配符正则表达式更强大,它能更精确地描述你的需求(当然你付出的代价是书写一个正则表达式比打出一个通配符要复杂得多,要知道任何给你带来好处的东西都是有代价的,就如同学习一门编程语言一样),比如你可以编写一个正则表达式,用来查找所有以0开头,后面跟着2-3个数字,然后是一个连字号“-”,最后是7或8位数字的字符串(像028-12345678或0813-7654321),这不就是国内的座机号码吗。最初计算机是为了做数学运算而诞生的,处理的信息基本上都是数值,而今天我们在日常工作中处理的信息基本上都是文本数据,我们希望计算机能够识别和处理符合某些模式的文本,正则表达式就显得非常重要了。今天几乎所有的编程语言都提供了对正则表达式操作的支持,Python通过标准库中的re模块来支持正则表达式操作。
我们可以考虑下面一个问题:我们从某个地方(可能是一个文本文件,也可能是网络上的一则新闻)获得了一个字符串,希望在字符串中找出手机号和座机号。当然我们可以设定手机号是11位的数字(注意并不是随机的11位数字,因为你没有见过“25012345678”这样的手机号吧)而座机号跟上一段中描述的模式相同,如果不使用正则表达式要完成这个任务就会很麻烦。
关于正则表达式的相关知识,大家可以阅读一篇非常有名的博客叫《正则表达式30分钟入门教程》,读完这篇文章后你就可以看懂下面的表格,这是我们对正则表达式中的一些基本符号进行的扼要总结。
说明: 如果需要匹配的字符是正则表达式中的特殊字符,那么可以使用\进行转义处理,例如想匹配小数点可以写成\.就可以了,因为直接写.会匹配任意字符;同理,想匹配圆括号必须写成\(和\),否则圆括号被视为正则表达式中的分组。
Python对正则表达式的支持
Python提供了re模块来支持正则表达式相关操作,下面是re模块中的核心函数。
说明: 上面提到的re模块中的这些函数,实际开发中也可以用正则表达式对象的方法替代对这些函数的使用,如果一个正则表达式需要重复的使用,那么先通过compile函数编译正则表达式并创建出正则表达式对象无疑是更为明智的选择。
下面我们通过一系列的例子来告诉大家在Python中如何使用正则表达式。
例子1:验证输入用户名和QQ号是否有效并给出对应的提示信息。
"""
验证输入用户名和QQ号是否有效并给出对应的提示信息
要求:用户名必须由字母、数字或下划线构成且长度在6~20个字符之间,QQ号是5~12的数字且首位不能为0
"""
import re
def main():
username = input('请输入用户名: ')
qq = input('请输入QQ号: ')
# match函数的第一个参数是正则表达式字符串或正则表达式对象
# 第二个参数是要跟正则表达式做匹配的字符串对象
m1 = re.match(r'^[0-9a-zA-Z_]{6,20}$', username)
if not m1:
print('请输入有效的用户名.')
m2 = re.match(r'^[1-9]\d{4,11}$', qq)
if not m2:
print('请输入有效的QQ号.')
if m1 and m2:
print('你输入的信息是有效的!')
if __name__ == '__main__':
main()
提示: 上面在书写正则表达式时使用了“原始字符串”的写法(在字符串前面加上了r),所谓“原始字符串”就是字符串中的每个字符都是它原始的意义,说得更直接一点就是字符串中没有所谓的转义字符啦。因为正则表达式中有很多元字符和需要进行转义的地方,如果不使用原始字符串就需要将反斜杠写作\\,例如表示数字的\d得书写成\\d,这样不仅写起来不方便,阅读的时候也会很吃力。
例子2:从一段文字中提取出国内手机号码。
下面这张图是截止到2017年底,国内三家运营商推出的手机号段。
import re
def main():
# 创建正则表达式对象 使用了前瞻和回顾来保证手机号前后不应该出现数字
pattern = re.compile(r'(?<=\D)1[34578]\d{9}(?=\D)')
sentence = '''
重要的事情说8130123456789遍,我的手机号是13512346789这个靓号,
不是15600998765,也是110或119,王大锤的手机号才是15600998765。
'''
# 查找所有匹配并保存到一个列表中
mylist = re.findall(pattern, sentence)
print(mylist)
print('--------华丽的分隔线--------')
# 通过迭代器取出匹配对象并获得匹配的内容
for temp in pattern.finditer(sentence):
print(temp.group())
print('--------华丽的分隔线--------')
# 通过search函数指定搜索位置找出所有匹配
m = pattern.search(sentence)
while m:
print(m.group())
m = pattern.search(sentence, m.end())
if __name__ == '__main__':
main()
说明: 上面匹配国内手机号的正则表达式并不够好,因为像14开头的号码只有145或147,而上面的正则表达式并没有考虑这种情况,要匹配国内手机号,更好的正则表达式的写法是:
(?<=\D)(1[38]\d{9}|14[57]\d{8}|15[0-35-9]\d{8}|17[678]\d{8})(?=\D)
,国内最近好像有19和16开头的手机号了,但是这个暂时不在我们考虑之列。
例子3:替换字符串中的不良内容
import re
def main():
sentence = '你丫是傻叉吗? 我操你大爷的. Fuck you.'
purified = re.sub('[操肏艹]|fuck|shit|傻[比屄逼叉缺吊屌]|煞笔',
'*', sentence, flags=re.IGNORECASE)
print(purified) # 你丫是*吗? 我*你大爷的. * you.
if __name__ == '__main__':
main()
说明: re模块的正则表达式相关函数中都有一个flags参数,它代表了正则表达式的匹配标记,可以通过该标记来指定匹配时是否忽略大小写、是否进行多行匹配、是否显示调试信息等。如果需要为flags参数指定多个值,可以使用按位或运算符进行叠加,如
flags=re.I | re.M
。
例子4:拆分长字符串
import re
def main():
poem = '窗前明月光,疑是地上霜。举头望明月,低头思故乡。'
sentence_list = re.split(r'[,。, .]', poem)
while '' in sentence_list:
sentence_list.remove('')
print(sentence_list) # ['窗前明月光', '疑是地上霜', '举头望明月', '低头思故乡']
if __name__ == '__main__':
main()
后话
如果要从事爬虫类应用的开发,那么正则表达式一定是一个非常好的助手,因为它可以帮助我们迅速的从网页代码中发现某种我们指定的模式并提取出我们需要的信息,当然对于初学者来收,要编写一个正确的适当的正则表达式可能并不是一件容易的事情(当然有些常用的正则表达式可以直接在网上找找),所以实际开发爬虫应用的时候,有很多人会选择Beautiful Soup或Lxml来进行匹配和信息的提取,前者简单方便但是性能较差,后者既好用性能也好,但是安装稍嫌麻烦,这些内容我们会在后期的爬虫专题中为大家介绍。
WeiboSpider
这可能是全网最强的微博爬虫项目![持续维护中]
项目说明
版本说明
该项目分为2个分支,以满足不同的需要
支持爬虫
- 用户信息抓取
- 用户微博抓取
- 用户社交关系抓取(粉丝/关注)
- 微博评论抓取
- 基于关键词和时间段的微博抓取
字段说明
项目基于weibo.cn站点抓取,抓取的字段非常丰富。具体请移步:数据字段说明
如何使用
拉取镜像
docker pull portainer/portainer
docker pull mongo
docker pull mongo-express
docker pull redis
docker pull registry.cn-hangzhou.aliyuncs.com/weibospider/account
docker pull registry.cn-hangzhou.aliyuncs.com/weibospider/spider
启动项目
docker stack deploy -c <(docker-compose config) weibospider
docker service ls
-----------------
ID NAME MODE REPLICAS IMAGE PORTS
f7yx1cjh1izt weibospider_portainer replicated 1/1 portainer/portainer:latest *:7000->9000/tcp
5szekv996su0 weibospider_mongodb replicated 1/1 mongo:latest *:7001->27017/tcp
lq7kmlekcrlg weibospider_mongo-express replicated 1/1 mongo-express:latest *:7002->8081/tcp
xjbddlf53hai weibospider_redis replicated 1/1 redis:latest *:7003->6379/tcp
mk8dmh6nl17i weibospider_account replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/account:latest
nvo9dt0r5v2t weibospider_weibo-spider-comment replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
vbnyacpm3xle weibospider_weibo-spider-fan replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
qyvu9wt0fzny weibospider_weibo-spider-follow replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
h3dfh8qr1eak weibospider_weibo-spider-tweet replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
jiaz176hzbls weibospider_weibo-spider-user replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
- portainer http://127.0.0.1:7000
通过portainer可以方便得对所有的服务进行管理,查看服务状态,运行日志。
通过scale
可快速进行服务的启动(置为1),停止(置为0),扩容(比如,置为100)

- mongo-express http://127.0.0.1:7002
通过mongo-express可以方便得查看管理mongo数据库

构建账号池
准备无验证码类型的微博小号, 免验证码的微博小号购买渠道在此讨论。
将购买的小号填充到./weibospider/account/account.txt
,格式与./weibospider/account/account_sample.txt
保持一致。
获取容器id,并进入容器
docker container ls | grep weibospider_account
1f15415443f8 registry.cn-hangzhou.aliyuncs.com/weibospider/account:latest "python3" 22 minutes ago Up 22 minutes weibospider_account.1.h091uc5sm0l1iz9oxpa7ypwak
docker exec -it 1f15415443f8 bash
root@1f15415443f8:/app#
构建账号池
root@1f15415443f8:/app# cd account
root@1f15415443f8:/app# python login.py
2020-04-15 11:56:56 ==============================
2020-04-15 11:56:56 start fetching cookie [zhanyuanben85c@163.com]
2020-04-15 11:57:04 cookie: _T_WM=0bfd51e7d3bdc1f914c5dbce3a4b20e0; SSOLoginState=1586923020; SUHB=010GS1NzSA-zOR; SCF=AmfAT-ydYBWL_ip0UMdV5KYFRwiWaFNTPoxWBgCc76c8PHXBkcp-CSNZArDRyyt1oShEm-T4Qukkw9W9n5eGrXA.; SUB=_2A25zkvZcDeRhGeFN71AY9i7FyzuIHXVRfJoUrDV6PUJbkdANLXjTkW1NQDAS-yKGeo_seRGTTKVAeOs1IG_ucher
2020-04-15 11:57:04 ==============================
2020-04-15 11:57:04 start fetching cookie [chuicong7188031104@163.com]
2020-04-15 11:57:11 cookie: _T_WM=6cf59fb4e2df7ba2b15e93d6bc184940; SSOLoginState=1586923028; SUHB=06ZV1_UTgTUirk; SCF=AvGBrUc4rNRZapeLXnQjOvrK9SyaN8dtGH_JfZamRkCRwCC6H1NJmJ6EVdZG26_lwfURJ233mRb5G-ZiM3WgGWA.; SUB=_2A25zkvZEDeRhGeFN71ET9S_Fzj6IHXVRfJoMrDV6PUJbkdANLRahkW1NQDAPyyhLB1NH_XSKtFoOQ2xwxkKWEMh5
2020-04-15 11:57:11 ==============================
2020-04-15 11:57:11 start fetching cookie [zhi21614055@163.com]
2020-04-15 11:57:19 cookie: _T_WM=6cc104aff523785aed114eb28996cb84; SSOLoginState=1586923035; SUHB=0bts1yfOjc42hI; SCF=AtAdd0uPAxdek8Hhh6JBOkxqFANmv7EqVebH6aHdY-3T_LUHoaIp6TaCo_57zCFZ-izJVcs01qs20b5cBpuwS_c.; SUB=_2A25zkvZLDeRhGeFN71AY9CjLwjuIHXVRfJoDrDV6PUJbkdANLWXjkW1NQDAJWlhRm6NkHCqHoOG9PBE1DOsaqX39
如果无法购买无验证码的小号也可以直接通过网页获取cookie, 修改insert_cookie函数的参数.
# 手工逐个添加构建
root@1f15415443f8:/app# python db_utils.py
添加代理IP
请重写fetch_proxy方法,该方法需要返回一个代理ip
初始化Redis
root@be3ac5910132:/app# python redis_init.py <arg>
参数arg可选项为:
user
: 初始化用户信息爬虫队列,对应weibospider_weibo-spider-user
docker服务fan
: 初始化用户粉丝列表爬虫队列,对应weibospider_weibo-spider-fan
docker服务follow
: 初始化用户关注列表爬虫队列,对应weibospider_weibo-spider-follow
docker服务comment
: 初始化微博评论爬虫队列,对应weibospider_weibo-spider-comment
docker服务tweet_by_user_id
: 初始化用户微博爬虫队列,对应weibospider_weibo-spider-tweet
docker服务tweet_by_keyword
: 初始化基于关键词和时间端的微博爬虫队列,对应weibospider_weibo-spider-tweet
docker服务
可根据自己的需求自行修改./weibospider/redis_init.py
下面以tweet_by_user_id
为例
root@be3ac5910132:/app# python redis_init.py tweet_by_user_id
Add urls to tweet_spider:start_urls
Added: https://weibo.cn/1087770692/profile?page=1
Added: https://weibo.cn/1699432410/profile?page=1
Added: https://weibo.cn/1266321801/profile?page=1
爬虫运行
爬虫程序使用会监测redis中是否有待抓取的URL,当redis初始化完毕爬虫就会自动运行了

在mongo-express中也可以看到实时抓取的数据

速度说明
分布式爬虫的最终速度和账号池的大小,IP代理的质量数量,服务器的带宽,服务器的性能(IO/内存/CPU)均有关系
下面是我测试的一组速度,供参考:
配置项 | 配置值 |
---|---|
账号池大小 | 1000+ |
IP池大小 | 50+ |
CONCURRENT_REQUESTS | 16 |
DOWNLOAD_DELAY | 0.1s |
DOWNLOAD_TIMEOUT | 3 |
爬虫容器个数 | 100 |
服务器带宽 | 30M |
服务器内存 | 256GB |
服务器CPU | E5-2650 v4 @ 2.20GHz * 48 |
经过测算,每个容器,每分钟网页抓取量:300+,一天抓取的网页为:
300(pages/(container*min)) * 100(containers) * 60*24(mins/day) = 43,200,000(pages/day)
4.3千万网页
如果抓取用户数据,1(data/page)
,则一天的数据抓取量为
43,200,000(pages/day) * 1(data/page) = 43,200,000(data/day)
4.3千万数据
如果抓取微博/评论/社交关系数据,10(data/page)
,则一天的数据抓取量为
43,200,000(pages/day) * 10(data/page) = 432,000,000(data/day)
4.3亿数据
写在最后
基于该项目已经构建千万级别的微博活跃用户数据集,以及海量的微博舆情数据集,现已公开weibo-public-opinion-datasets
如果您在使用该项目中有任何问题,均可以开issue进行讨论
如果您在社交媒体计算/舆情分析等领域上有好的idea,欢迎一起交流合作: nghuyong@163.com
WeiboSpider
This may be the most powerful Weibo spider in the whole Internet[Ongoing maintenance]
Introduction
Branches
The project has 2 branches to meet different needs:
Branch | Features | Magnitude of the crawled data |
---|---|---|
simple | Single account, single IP, single machine | Hundreds of thousands |
master | Account pool, IP pool, Docker | Hundreds of millions(Theoretical unlimited) |
Supported crawling types
- User Information
- Tweets post by user
- Users' social relationships (fans/followers)
- Comments of tweets
- Tweets based on keywords and time period
Data Structure
The spider based on the weibo.cn
, and the crawled fields are very rich. More detail: Data Structure Description
Get Started
Pull Docker images
docker pull portainer/portainer
docker pull mongo
docker pull mongo-express
docker pull redis
docker pull registry.cn-hangzhou.aliyuncs.com/weibospider/account
docker pull registry.cn-hangzhou.aliyuncs.com/weibospider/spider
Run the project
docker stack deploy -c <(docker-compose config) weibospider
docker service ls
-----------------
ID NAME MODE REPLICAS IMAGE PORTS
f7yx1cjh1izt weibospider_portainer replicated 1/1 portainer/portainer:latest *:7000->9000/tcp
5szekv996su0 weibospider_mongodb replicated 1/1 mongo:latest *:7001->27017/tcp
lq7kmlekcrlg weibospider_mongo-express replicated 1/1 mongo-express:latest *:7002->8081/tcp
xjbddlf53hai weibospider_redis replicated 1/1 redis:latest *:7003->6379/tcp
mk8dmh6nl17i weibospider_account replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/account:latest
nvo9dt0r5v2t weibospider_weibo-spider-comment replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
vbnyacpm3xle weibospider_weibo-spider-fan replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
qyvu9wt0fzny weibospider_weibo-spider-follow replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
h3dfh8qr1eak weibospider_weibo-spider-tweet replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
jiaz176hzbls weibospider_weibo-spider-user replicated 1/1 registry.cn-hangzhou.aliyuncs.com/weibospider/spider:latest
- portainer http://127.0.0.1:7000
Through the portainer, we can easily manage all services, monitor the service status, and view logs of services.
Through the setting of scale
, we can quickly run the service (set to 1), stop the service (set to 0), and expand the service (such as, set to 100).

- mongo-express http://127.0.0.1:7002
We can easily manage mongodb through mongo-express.

Build Account Pool
Prepare accounts without verification code, we will discuss at here.
Fill the purchased accounts into the file./weibospider/account/account.txt
, and the format should be the same as ./weibospider/account/account_sample.txt
Get the container id of account_service
and enter into the container.
docker container ls | grep weibospider_account
1f15415443f8 registry.cn-hangzhou.aliyuncs.com/weibospider/account:latest "python3" 22 minutes ago Up 22 minutes weibospider_account.1.h091uc5sm0l1iz9oxpa7ypwak
docker exec -it 1f15415443f8 bash
root@1f15415443f8:/app#
Build accounts pool
root@1f15415443f8:/app# cd account
root@1f15415443f8:/app# python login.py
2020-04-15 11:56:56 ==============================
2020-04-15 11:56:56 start fetching cookie [zhanyuanben85c@163.com]
2020-04-15 11:57:04 cookie: _T_WM=0bfd51e7d3bdc1f914c5dbce3a4b20e0; SSOLoginState=1586923020; SUHB=010GS1NzSA-zOR; SCF=AmfAT-ydYBWL_ip0UMdV5KYFRwiWaFNTPoxWBgCc76c8PHXBkcp-CSNZArDRyyt1oShEm-T4Qukkw9W9n5eGrXA.; SUB=_2A25zkvZcDeRhGeFN71AY9i7FyzuIHXVRfJoUrDV6PUJbkdANLXjTkW1NQDAS-yKGeo_seRGTTKVAeOs1IG_ucher
2020-04-15 11:57:04 ==============================
2020-04-15 11:57:04 start fetching cookie [chuicong7188031104@163.com]
2020-04-15 11:57:11 cookie: _T_WM=6cf59fb4e2df7ba2b15e93d6bc184940; SSOLoginState=1586923028; SUHB=06ZV1_UTgTUirk; SCF=AvGBrUc4rNRZapeLXnQjOvrK9SyaN8dtGH_JfZamRkCRwCC6H1NJmJ6EVdZG26_lwfURJ233mRb5G-ZiM3WgGWA.; SUB=_2A25zkvZEDeRhGeFN71ET9S_Fzj6IHXVRfJoMrDV6PUJbkdANLRahkW1NQDAPyyhLB1NH_XSKtFoOQ2xwxkKWEMh5
2020-04-15 11:57:11 ==============================
2020-04-15 11:57:11 start fetching cookie [zhi21614055@163.com]
2020-04-15 11:57:19 cookie: _T_WM=6cc104aff523785aed114eb28996cb84; SSOLoginState=1586923035; SUHB=0bts1yfOjc42hI; SCF=AtAdd0uPAxdek8Hhh6JBOkxqFANmv7EqVebH6aHdY-3T_LUHoaIp6TaCo_57zCFZ-izJVcs01qs20b5cBpuwS_c.; SUB=_2A25zkvZLDeRhGeFN71AY9CjLwjuIHXVRfJoDrDV6PUJbkdANLWXjkW1NQDAJWlhRm6NkHCqHoOG9PBE1DOsaqX39
If you can’t buy accounts without a verification code, you can also get cookies directly from the web, Modify the parameters of insert_cookie.
# Add cookie one by one manually
root@1f15415443f8:/app# python db_utils.py
Add Proxy IP
Rewrite the function fetch_proxy.
Init Redis
root@be3ac5910132:/app# python redis_init.py <arg>
The arg
could be:
user
: Initialize the user information crawler queue, corresponding toweibospider_weibo-spider-user
fan
: Initialize the fans crawler queue, corresponding toweibospider_weibo-spider-fan
follow
: Initialize the follow crawler queue, corresponding toweibospider_weibo-spider-follow
comment
: Initialize the comment crawler queue, corresponding toweibospider_weibo-spider-comment
tweet_by_user_id
: Initialize the tweets based on users crawler queue, corresponding toweibospider_weibo-spider-tweet
tweet_by_keyword
: Initialize the tweets based on keywords and time crawler queue, corresponding toweibospider_weibo-spider-tweet
You can modify the ./weibospider/redis_init.py
according to your needs.
We take the arg to be tweet_by_user_id
as example:
root@be3ac5910132:/app# python redis_init.py tweet_by_user_id
Add urls to tweet_spider:start_urls
Added: https://weibo.cn/1087770692/profile?page=1
Added: https://weibo.cn/1699432410/profile?page=1
Added: https://weibo.cn/1266321801/profile?page=1
Run Spider
The spider will monitor whether the corresponding queue in the redis has urls, and when the queue has urls, the spider will auto run to crawl data.

We can see the real-time crawled data by mongo-express

Note for Speed
The final speed of the distributed crawler is related to the size of the account pool, the quality and quantity of the IP proxy, the bandwidth of the server, and the performance of the server (IO / memory / CPU).
The following is the settings and the corresponding speeds I tested for reference:
Settings | Value |
---|---|
size of the account pool | 1000+ |
size of the proxy IP pool | 50+ |
CONCURRENT_REQUESTS | 16 |
DOWNLOAD_DELAY | 0.1s |
DOWNLOAD_TIMEOUT | 3 |
numbers of spider containers | 100 |
bandwidth of the server | 30M |
memory of the server | 256GB |
CPU of the server | E5-2650 v4 @ 2.20GHz * 48 |
The result is that the number of crawled web pages per container and per minute is: 300+, and the numbers of web pages crawled in one day is:
300(pages/(container*min)) * 100(containers) * 60*24(mins/day) = 43,200,000(pages/day)
43 million web pages
If we crawl data of user information,1(data/page)
, the amount of data crawled in one day is:
43,200,000(pages/day) * 1(data/page) = 43,200,000(data/day)
43 million
If we crawl data of tweet/comment/relationship,10(data/page)
, the amount of data crawled in one day is:
43,200,000(pages/day) * 10(data/page) = 432,000,000(data/day)
4.3 billion
Last But Not The Least
Based on this project, I have crawled millions weibo active user data, and have built many weibo public opinion datasets: weibo-public-opinion-datasets.
If you have any problems in using the project, you can open an issue to discuss.
If you have good ideas in social media computing / public opinion analysis, feel free to email me: nghuyong@163.com
:hehe:
:weixiao:
[微笑]
哈哈好玩
哈哈哈挺好玩的