Crawling eye teeth Popular anchor game analysis of actual combat

Crawling eye teeth Popular anchor game analysis of combat:

 

 

In the event he got the time to write a few pit, and then fill up:

the first is:

I would like to begin with crawling anchor Popularity: but can not find div find only span the next encounter </ span> is over but unfortunately only to find the next element

Find the next </ li> tag just popular digital included. The first problem to solve

 

second question:

FML ah, really the day of the dog, which they then have to match the title at the contents inside otherwise not get the data

name_pattern = '<i class="nick" title="[\s\S]*?">
l:

 

import re
from urllib import request #导入url请求的模块
class Spider():
    url = 'https://www.huya.com/g/wzry'
    root_pattern = '<span class="txt">([\s\S]*?)</li>' #中间的正则表示其中的内容
    name_pattern = '<i class="nick" title="[\s\S]*?">([\s\S]*?)</i>'
    number_pattern = '<i class="js-num">([\s\S]*?)</i>'
    def __fetch_content(self):
        r = request.urlopen(Spider.url)
        htmls = r.read()
        htmls = str(htmls,encoding='utf-8')
        return htmls
    def __analysis(self,htmls):
        root_html = re.findall(Spider.root_pattern,htmls)#使用正则传入参数匹配结果
        anchors = []
        for html in root_html:
            name = re.findall(Spider.name_pattern,html)
            number = re.findall(Spider.number_pattern,html)
            anchor = {'name':name,'number':number}
            anchors.append(anchor)
        return anchors
    def __refine(self,anchors):#精炼数据
        l = lambda anchor:{
            'name':anchor['name'][0].strip(),
            'number':anchor['number'][0]
                           }
        return map(l,anchors)
    def __sort(self,anchors):
        anchors = sorted(anchors,key=self.__sort_seed,reverse=True) #排序
        return anchors
    def __sort_seed(self,anchor):
        r = re.findall('\d*',anchor['number'])
        number = float(r[0])
        if '万' in anchor['number']:
            number = number*10000
        return number
    def __show(self,anchors):
        for rank in range(0,len(anchors)):
            print('第' +str(rank+1)+"名"
            +'  :  '+anchors[rank]['name']
            +'  :  '+anchors[rank]['number'])


    def go(self): #入口方法
        htmls  = self.__fetch_content()
        anchors = self.__analysis(htmls)
        anchors = list(self.__refine(anchors))
        anchors = self.__sort(anchors)
        self.__show(anchors)
        # print(anchors)
spider = Spider();
spider.go()

结果:

 

C:\Users\User\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/User/PycharmProjects/untitled/Spider/Spider.py

第1名  :  云图-猴三棍  :  133.5万

第2名  :  东辰-寒冰  :  82.2万

第3名  :  Dae-小潮  :  51.8万

第4名  :  KPL职业联赛  :  47.9万

第5名  :  正恒丶夕阳  :  39.9万

第6名  :  EL-往事zr  :  31.4万

第7名  :  曹操大表哥  :  17.7万

第8名  :  寒夜GodLike  :  15.9万

第9名  :  雨雾-大雪碧  :  12.5万

第10名  :  老四解说  :  12.4万

第11名  :  东辰-像风  :  10.4万

第12名  :  暖心男神锐雯  :  9.9万

第13名  :  德古拉  :  8.6万

第14名  :  逐梦-念青  :  7.2万

第15名  :  正恒-愿望  :  7.9万

第16名  :  EL-童子  :  6.2万

第17名  :  与世无争傲寒  :  6.8万

第18名  :  虎牙风油精  :  5.8万

第19名  :  LD-U倪  :  4.5万

第20名  :  YTG路西法-Dae  :  3.6万

第21名  :  AzZ丶沧海  :  3.9万

第22名  :  久帝-萌6  :  3.2万

第23名  :  丹海-荒神  :  3.3万

第24名  :  虎牙帝王  :  3.1万

第25名  :  LD-布衣  :  3.0万

第26名  :  久帝-小钢蹦  :  2.1万

第27名  :  BA黑凤梨-一诺  :  2.7万

第28名  :  大锤哥-云图CD  :  2.5万

第29名  :  BA黑凤梨-六点六  :  2.4万

第30名  :  铭星丶紫宸  :  2.9万

第31名  :  Dx-呆萌鹿乃  :  2.8万

第32名  :  爱拍-南瓜  :  2.6万

第33名  :  创红-逸羽  :  2.6万

第34名  :  东辰-晨琳  :  2.2万

第35名  :  畅玩-小宝专业带粉  :  2.2万

第36名  :  红豆世无双  :  2.1万

第37名  :  蓝新-夜夜  :  2.0万

第38名  :  LD-小飞  :  2.0万

第39名  :  AzZ丶夕雅  :  1.7万

第40名  :  影娱-小奶茶  :  1.8万

第41名  :  东辰-乔治  :  1.0万

第42名  :  Dx-夏目  :  1.7万

第43名  :  东辰-豆芽  :  1.7万

第44名  :  G-阿华  :  1.6万

第45名  :  豆芽  :  1.6万

第46名  :  铭星丶啊瞬  :  1.6万

第47名  :  星游-仙备  :  1.5万

第48名  :  东辰-甜味阿诗  :  1.5万

第49名  :  非凡-李筱筱  :  1.5万

第50名  :  正恒、叮当猫  :  1.4万

第51名  :  盛夏-糖糖酱  :  1.4万

第52名  :  火花  :  1.4万

第53名  :  大乐-泽泽酱  :  1.4万

第54名  :  东辰-晚来疯  :  1.3万

第55名  :  正恒丶薇儿  :  1.3万

第56名  :  虎牙丶猫老师  :  1.3万

第57名  :  DK-白老怂  :  1.3万

第58名  :  虎牙小年糕  :  1.3万

第59名  :  TTT豪酱  :  1.2万

第60名  :  小尾巴  :  1.2万

第61名  :  正恒丶啊毛  :  1.2万

第62名  :  Yx9丶太乙  :  1.2万

第63名  :  Fun、名辞  :  1.2万

第64名  :  你的阿深吖  :  1.2万

第65名  :  奇点  :  1.2万

第66名  :  久帝-暖羊  :  1.2万

第67名  :  LD-小虎  :  1.1万

第68名  :  鹿语-情某  :  1.1万

第69名  :  乐轩-辉少  :  1.1万

第70名  :  傲辰-旧琴  :  1.1万

第71名  :  过儿  :  1.1万

第72名  :  LB-赵灵儿  :  1.1万

第73名  :  中国蓝丶摩王  :  1.1万

第74名  :  英杰丶呆少  :  1.1万

第75名  :  MH丶CC果  :  1.0万

第76名  :  虎牙-嘉骆  :  1.0万

第77名  :  HtC-九黎  :  1.0万

第78名  :  葫芦岛丶8娃  :  9929

第79名  :  鑫洋-方木阿  :  9906

第80名  :  Yx9丶刘当时  :  9896

第81名  :  逐梦-绅秋  :  9883

第82名  :  时针Show  :  9714

第83名  :  辰白-寒暄  :  9693

第84名  :  沐颜  :  9405

第85名  :  Fun、男神  :  9278

第86名  :  东辰-田田  :  9265

第87名  :  东辰-怪咖  :  9234

第88名  :  TTT-默默  :  9196

第89名  :  辰白-史努比  :  9190

第90名  :  AzZ丶碎星  :  9112

第91名  :  AzZ丶阿平  :  8982

第92名  :  虎牙丶梦枪  :  8941

第93名  :  星点丶浪子  :  8879

第94名  :  AzZ丶小西瓜  :  8824

第95名  :  小顽童  :  8811

第96名  :  蓝新-皮皮离  :  8716

第97名  :  叶尘  :  8644

第98名  :  Dx-蓝莓  :  8640

第99名  :  西木  :  8619

第100名  :  东辰-董小姐  :  8599

第101名  :  逐梦-孤城  :  8588

第102名  :  Unk-小宇  :  8489

第103名  :  栀白  :  8472

第104名  :  LD-冰一  :  8420

第105名  :  虎承  :  8301

第106名  :  海龟先生777  :  8269

第107名  :  天亿-小波妹  :  8139

第108名  :  BA黑凤梨-麟羽轩  :  7666

第109名  :  久帝-绘梨衣  :  7559

第110名  :  AzZ丶樱花月  :  7140

第111名  :  JQK丶阿超  :  6797

第112名  :  血色-骚小黑  :  6403

第113名  :  圈圈  :  5692

第114名  :  久帝瑶瑶  :  4584

第115名  :  EL-小燕子  :  4419

第116名  :  久帝-Fendi  :  3299

第117名  :  东辰-猫猫  :  2776

第118名  :  BA黑凤梨-小剑  :  2758

第119名  :  BA黑凤梨-139  :  1846

第120名  :  正恒pop-小仔  :  1

 

Process finished with exit code 0

 

Guess you like

Origin blog.csdn.net/qq_41479464/article/details/91048147