import re
import requests
from urllib import request
class Spider():
url = 'https://www.panda.tv/cate/lol?pdt=1.c_lol.psbar-ca0.0.4mlne1135jo'
root_parttern = '<div class="video-info">([\s\S]*?)</div>'
name_parttern = ' data-level="[0-9]{0,2}"></i>([\s\S]*?)</span>'
number_parttern = '<i class="ricon ricon-eye"></i>([\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_parttern, htmls)
anchors = []
for html in root_html:
name = re.findall(Spider.name_parttern,html)
number = re.findall(Spider.number_parttern,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()