鱼C论坛

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

[已解决]爬虫

[复制链接]
发表于 2018-1-4 16:20:29 | 显示全部楼层 |阅读模式

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

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

x
哪个大神帮我看看这个爬虫,是爬爱奇艺VIP视频的,不知道为什么这个只能爬九个,麻烦帮我改一下



import requests
import re
import sys


type = sys.getfilesystemencoding()

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)\
Chrome/55.0.2883.87 Safari/537.36'}
html = requests.get('http://vip.iqiyi.com/hot.html?cid=1',headers=headers)
html.encoding = 'utf-8'
title = re.findall('<a target="_blank" rseat="709181_热播榜二级页_电影(.)" title="(.*?)"',html.text,re.S)
for each in title:
    print(each)
最佳答案
2018-1-4 19:02:32
讲来讲去,还是正则表达式没有写对:
  1. import requests
  2. import re
  3. import sys


  4. type = sys.getfilesystemencoding()

  5. headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)\
  6. Chrome/55.0.2883.87 Safari/537.36'}
  7. html = requests.get('http://vip.iqiyi.com/hot.html?cid=1',headers=headers)
  8. html.encoding = 'utf-8'
  9. title = re.findall(r'<a target="_blank" rseat="709181_热播榜二级页_电影(.*?)" title="(.*?)"',html.text,re.S)
  10. for each in title:
  11.     print(each)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-4 19:02:32 | 显示全部楼层    本楼为最佳答案   
讲来讲去,还是正则表达式没有写对:
  1. import requests
  2. import re
  3. import sys


  4. type = sys.getfilesystemencoding()

  5. headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)\
  6. Chrome/55.0.2883.87 Safari/537.36'}
  7. html = requests.get('http://vip.iqiyi.com/hot.html?cid=1',headers=headers)
  8. html.encoding = 'utf-8'
  9. title = re.findall(r'<a target="_blank" rseat="709181_热播榜二级页_电影(.*?)" title="(.*?)"',html.text,re.S)
  10. for each in title:
  11.     print(each)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-7 16:12:09 | 显示全部楼层
ba21 发表于 2018-1-4 19:02
讲来讲去,还是正则表达式没有写对:

正则表达式那少写了一个r吗?为什么一定要加呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-17 02:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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