鱼C论坛

 找回密码
 立即注册
查看: 893|回复: 1

《Python第二版》中爬虫文件的问题

[复制链接]
发表于 2019-7-27 16:43:43 | 显示全部楼层 |阅读模式

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

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

x
这一段代码 是小甲鱼老师改的爬百度贴吧上图片的 这里代码的问题看不懂
  1. import urllib.request
  2. import re
  3. import os
  4. import requests

  5. def open_url(url):
  6.     req = urllib.request.Request(url)
  7.     req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36')
  8.     page = urllib.request.urlopen(req)
  9.     html = page.read().decode('utf-8')
  10.     return html


  11. def get_img(html):
  12.     p = r'<img class="BDE_Image".*?src="[^"]*\.jpg)".*?>'
  13.     imglist = re.findall(p,html)

  14.     try:
  15.         os.mkdir('NewPics')
  16.     except FileExistsError:
  17.         pass

  18.     os.chdir('NewPics')

  19.     for each in imglist:
  20.         filename = each.split("/")[-1]
  21.         urllib.request.urlretrieve(each,filename,None)

  22. if __name__=='__main__':
  23.     url = 'http://tieba.baidu.com/p/3823765471'
  24.     get_img(open_url(url))
复制代码


但是最后报错的内容我看不懂
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-7-27 16:44:27 | 显示全部楼层
File "F:\python\lib\re.py", line 223, in findall
    return _compile(pattern, flags).findall(string)
  File "F:\python\lib\re.py", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "F:\python\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "F:\python\lib\sre_parse.py", line 944, in parse
    raise source.error("unbalanced parenthesis")
re.error: unbalanced parenthesis at position 40


没见过这一段报错 请问各位大佬这个怎么改
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-17 06:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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