使用fiddler抓包工具,抓取斗鱼接口,爬取数据

使用fiddler抓包工具,分析斗鱼接口信息找到斗鱼接口url,进行接口分析,提取数据。由于斗鱼直播数据和整个页面页码都是根据开播来实时更新的。所以我们提取数据是要判断。拿到实时的页码。

import requests
import random

'''
url = https://www.douyu.com/gapi/rkc/directory/0_0/list

'''
def get_douyu_api(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'
    }
    proxies_list = [
         {
             'http': 'http://218.95.37.252:3128',
             'https': 'https://182.61.162.160:3128'
         },
         {
             'http': 'http://163.125.19.53:8888',
             'https': 'https://221.229.252.98:8080'
         },
    

    ]
    proxies = random.choice(proxies_list)
    print(proxies)
    response = requests.get(url, headers=headers,proxies=proxies).json()
    # 一个接口里120条数据(1页)
    for i in range(120):
        try:
            # 直播标题
            title = response['data']['rl'][i]['rn']
            # print(title)
        except:
            title = '无标题'
        try:
            # 直播类型
            type1 = response['data']['rl'][i]['c2name']
            # print(type1)
        except:
            type1 = '无类型'
        try:
            # 主播名
            name = response['data']['rl'][i]['nn']
            # print(name)
        except:
            name = '无用户'
        try:
            # 热度
            hot = response['data']['rl'][i]['ol']
            # print(hot)
        except:
            hot = '无热度'
        info = f"直播类型:{type1},直播标题:{title},主播名:{name},热度:{hot}"
        print(info)
        with open('斗鱼.txt','a',encoding='utf-8')as fp:
            fp.write(info+'\n')
    # 总页数
    pgcnt = response['data']['pgcnt']
    return pgcnt
    # print(pgcnt)

if __name__ == '__main__':
    i = 1
    while True:
        url = f'https://www.douyu.com/gapi/rkc/directory/0_0/{i}'
        pgcnt = get_douyu_api(url)
        i += 1
        if i > pgcnt:
            break
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孜孜孜孜不倦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值