当前位置:   article > 正文

爬取斗鱼直播并分析数据_爬取斗鱼直播数据

爬取斗鱼直播数据
"""
auth:Brussels
"""
import requests
import time


class DouYu(object):

    def __init__(self):
        self.url = 'https://www.douyu.com/gapi/rkc/directory/0_0/'
        self.page = 1
        self.num = 1
        self.artist_info = {
   }
        self.total_hot = 0
        self.flag = 1

    def __get_response(self):  # 请求接口,返回响应
        res = requests.get(self.url+str(self.page))
        response = res.json()
        return response

    def __get_first_name(self):  # 拿到第一页第一个的主播姓名,用来判断循环重复
        url = 'https://www.douyu.com/gapi/rkc/directory/0_0/1'
        res = requests.get(url)
        response = res.json()
        first_name = response['data']['rl'][0]['nn']
        return first_name

    def get_artist_info(self):
        first_name = self.__get_first_name()  # 得到当前排名第一个主播姓名,用来判断循环结束

        while DouYu.flag == 1:
            response = self.__get_response()
            self.info = response['data']['rl']
            for i in range(len(self.info)):
                self.info = response['data']['rl']
                name = self.info[i]['nn']<
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号