import re
from urllib import request
class Spider():
url = '
https://www.panda.tv/cate/lol?pdt=1.24.s1.3.15r0uaprii3' 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_html = re.findall(Spider.root_pattern,htmls)
anchors = []
for html in root_html:
name = re.findall(Spider.name_pattern,html)
nember = re.findall(Spider.number_pattern,html)
anchor = {'nema':name,'nember':nember}
anchors.append(anchor)
return anchors
def __refine(self,anchors):
l = lambda anchor: {
'name':anchor['name'][0].strip(),
'nember':anchor['nember'][0]
}
return map(l , anchors)
def __sort(self,anchors):
anchors = sorted(anchors,key=self.__sort_seed)
return anchors
def __sort_seed(self,anchor):
return anchor['nember']
def __show(self,anchors):
for anchor in anchors:
print(anchor['name'] + '————' + anchor['nember'])
def go(self):
htmls = self.__fetch_content()
anchors = self.__analysis(htmls)
anchors = list(self.__refine(anchors))
anchors = self.__sort(anchors)
self.__show(anchors)
spider = Spider()
spider.go()
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/504273
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.