请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

为什么这里的name和number传不进去

import re

from urllib import request


class Spider():

url = 'https://www.panda.tv/cate/lol'

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")   #htmls字符串转译

return htmls


def __analysis(self,htmls):

anchors = []  #在外面添加一个list方法

root_html = re.findall(Spider.root_pattern,htmls)

for html in root_html:   #用for查找name和number

name = re.findall(Spider.name_pattern,html)

number = re.findall(Spider.number_pattern,html)

anchor = {'name':name,'number':number}  #把name和number拼成一个字典

anchors.append(anchor) #将list里的元素添加  用append方法

print(anchors[0])


def refine():        #精炼数据

pass

def go(self):

htmls=self.__fetch_content()  #

self.__analysis(htmls)


spider=Spider()

spider.go()

https://img1.sycdn.imooc.com//szimg/5a9698b90001060f19201058.jpg

正在回答

2回答

传不进去是什么意思?可以标注一下吗,到底哪里错了,错误信息也没看到。

0 回复 有任何疑惑可以回复我~
提问者 qq_八面玲珑安分孩子_04385969 2018-03-01 08:59:51

https://img1.sycdn.imooc.com//szimg/5a97504f000128dc19191050.jpg在图上做了标注

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号