赞
踩
大年初七了还不开始学习嘛?
过年期间一直再在看斗鱼直播平台的直播,学习主播的操作(骚套路)想着等有机会也来实战一波。看着看着就很想分析一下到底哪些主播观看的人数比较多,又为啥会有这么多人看。所以我们就要用爬虫来采集斗鱼直播平台上的数据了。
准
import requests
url="https://www.douyu.com/gapi/rkc/directory/2_270/1"
header={
"accept":" text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'
}
req=requests.get(url)#获取响应
x=req.json()#获取json数据 等同于json.loads(response.text)方法
for i in range(0,len(x['data']['rl'])):
print(str(i)+":"+
"主播名字:"+x['data']['rl'][i]['nn']+
" 主播标题:"+x['data']['rl'][i]['rn']+
" 火热度:"+str(x['data']['rl'][i]['ol'])+'\n'+
"主播地址:"+"https://www.douyu.com"+x['data']['rl'][i]['url']+
" 图片地址:"+x['data']['rl'][i]['rs1'])
结果展示
其实爬虫就这么简单,欢迎指导交流哟
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。