鱼C论坛

 找回密码
 立即注册
查看: 585|回复: 3

一个简单的爬虫,求大佬帮我检查错在哪里

[复制链接]
发表于 2018-6-17 16:53:25 | 显示全部楼层 |阅读模式

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

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

x
from urllib import request
import re


class Spider():
        url = "https://www.panda.tv/cate/lol?pdt=1.24.s1.3.2c6qoma1l34"
        root_pattern = '<div class="video-info">([\s\S]*?)</div>'
        name_pattern = '</i>([\s\S*?])</span>'
        number_pattern = '<span class="video-number"></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_htmls = re.findall(Spider.root_pattern,htmls)
                anchors = []
                for html in root_htmls:
                        name = re.findall(Spider.name_pattern,root_htmls)
                        number = re.findall(Spider.number_pattern,root_htmls)
                        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)
        
s = Spider()
s.go()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-17 18:28:41 | 显示全部楼层
root_htmls转成str类型
  1. str(root_htmls)
复制代码

正则表达式对不对就不知道了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-17 19:15:26 | 显示全部楼层
Charles未晞 发表于 2018-6-17 18:28
root_htmls转成str类型

正则表达式对不对就不知道了


                               
登录/注册后可看大图
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-17 22:31:22 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 01:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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