鱼C论坛

 找回密码
 立即注册
查看: 652|回复: 2

又卡这了,求大佬指点

[复制链接]
发表于 2018-12-28 19:17:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import re
from urllib import request
class Spider():
    ur1 = "https://www.panda.tv/cate/lol"
    root_pattern = '<div class="video-info">([\s\S]*?)</div>'
    name_pattern = '</i>([\s\S]*?)</span>'
    namer_pattern ='</i>([\s\S]*?)</span>'
    def __fetch_content(self):
        r = request.urlopen(Spider.ur1)
        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 abc in root_html:
            name = re.findall(Spider.name_pattern,abc)
            number = re.findall(Spider.namer_pattern,abc)
            anchor = {'name':name,'number':number}
            anchors.append(anchor)
        print(anchors)
        a = 1
    def __refine(self,anchors):
        a = lambda anchor:{
            'name':anchor['name'][0].strip(),
            'number':anchor['number'][0]
            }
        return map(a, anchors)   
   
    def go(self):
        htmls = self.__fetch_content()
        anchors = self.__analysis(htmls)
        anchors = list(self.__refine(anchors))
        print(anchors)
        
   
spider = Spider()
spider.go()
啊啊啊  为什么会报对象不可迭代啊
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-29 19:32:20 | 显示全部楼层
不要发这么长代码,告诉我们,这些代码是干什么用的。系统是不是提示报错了,报错内容发一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-12-29 20:18:32 | 显示全部楼层
飘香一剑 发表于 2018-12-29 19:32
不要发这么长代码,告诉我们,这些代码是干什么用的。系统是不是提示报错了,报错内容发一下

感谢 昨天已经找着报错 的原因了  麻烦了下次在发代码的时候会注意点的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-10 23:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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