鱼C论坛

 找回密码
 立即注册
查看: 734|回复: 3

错误提示

[复制链接]
发表于 2018-6-17 19:25:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这是什么啥错误
M3))5O}H%@)}}FJQB`FB[DB.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-17 19:33:16 | 显示全部楼层
空格和tab键不能混用。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2018-6-17 21:20:19 | 显示全部楼层
新手·ing 发表于 2018-6-17 19:33
空格和tab键不能混用。
from urllib import request
import re


class Spider():
        url = "https://www.panda.tv/cate/lol?pdt=1.24.s1.3.2c6qoma1l34"
        root_pattern = '<div class="video-info">([\s\S]*?)</div>'
        name_pattern = '</i>([\s\S]+?)</span>'
        number_pattern = '<span class="video-number">([\s\S]+?)</span>'
        
        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_htmls = re.findall(Spider.root_pattern,htmls)
                anchors = []
                #print(root_htmls[0])
                
                for html in root_htmls:
                        name = re.findall(Spider.name_pattern,html)
                        number = re.findall(Spider.number_pattern,html)
                        anchor = {'name':name,'number':number}
                        anchors.append(anchor)
                #print(anchors[0])
                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.__sort1)

        def __sort1(self,anchor):
                r = re.findall("\d*",anchor['number'])
                number = float(r)
                if "万" in anchor['number']:
                        number *= 10000
                return number

                
        def __show(self,anchors):
                for i in anchors:
                        print(i['name'] + '------>' + i['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[0])
        
s = Spider()
s.go()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-17 21:21:02 | 显示全部楼层
新手·ing 发表于 2018-6-17 19:33
空格和tab键不能混用。

帮忙看一下这个该怎么改
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-30 18:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表