鱼C论坛

 找回密码
 立即注册
查看: 691|回复: 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键不能混用。
  1. from urllib import request
  2. import re


  3. class Spider():
  4.         url = "https://www.panda.tv/cate/lol?pdt=1.24.s1.3.2c6qoma1l34"
  5.         root_pattern = '<div class="video-info">([\s\S]*?)</div>'
  6.         name_pattern = '</i>([\s\S]+?)</span>'
  7.         number_pattern = '<span class="video-number">([\s\S]+?)</span>'
  8.        
  9.         def __fetch_content(self):
  10.                 r = request.urlopen(Spider.url)
  11.                 htmls = r.read()
  12.                 htmls = str(htmls,encoding = "utf-8")
  13.                 return htmls
  14.                
  15.         def __analysis(self,htmls):
  16.                 root_htmls = re.findall(Spider.root_pattern,htmls)
  17.                 anchors = []
  18.                 #print(root_htmls[0])
  19.                
  20.                 for html in root_htmls:
  21.                         name = re.findall(Spider.name_pattern,html)
  22.                         number = re.findall(Spider.number_pattern,html)
  23.                         anchor = {'name':name,'number':number}
  24.                         anchors.append(anchor)
  25.                 #print(anchors[0])
  26.                 return anchors
  27.                
  28.         def __refine(self,anchors):
  29.                 l = lambda anchor:{'name':anchor['name'][0].strip(),'number':anchor['number'][0]}
  30.                 return map(l,anchors)
  31.                
  32.         def __sort(self,anchors):
  33.                 anchors = sorted(anchors,key =self.__sort1)

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

  40.                
  41.         def __show(self,anchors):
  42.                 for i in anchors:
  43.                         print(i['name'] + '------>' + i['number'])
  44.        
  45.        
  46.         def go(self):
  47.                 htmls = self.__fetch_content()
  48.                 anchors = self.__analysis(htmls)
  49.                 anchors = list(self.__refine(anchors))
  50.                 anchors = self.__sort(anchors)
  51.                 self.__show(anchors)
  52.                
  53.                 #print(anchors[0])
  54.        
  55. s = Spider()
  56. 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-3-29 13:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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