list index out of range
来源:13-9 数据精炼
慕斯卡7430980
2019-03-26
import re
from urllib import request
断点调试
class Spider():
url=‘https://www.panda.tv/cate/lol’
root_pattern=’
[\s\S]?
‘name_pattern=’([\s\S]?)‘
num_pattern=’([\s\S]*?)'
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.num_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 go(self):
htmls=self.__fetch_content()
anchors=self.__analysis(htmls)
anchors=list(self.__refine(anchors))
print(anchors)
spider=Spider()
spider.go()
写回答
1回答
-
换斗鱼爬,熊猫 没什么数据了 现在。
022019-03-28
相似问题