python
import urllib.requestimport re
response = urllib.request.urlopen('https://tieba.baidu.com/p/6812722163')
html = response.read().decode('utf-8')
p = r'<img class="BDE_Image".*?src="[^"]*\.jpg".*?>'
imglist = re.findall(p.html)
for each in imglist:
print(each)
为什么会出现
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/新建文件夹/39.py", line 6, in <module>
imglist = re.findall(p.html)
AttributeError: 'str' object has no attribute 'html'
这样的错误。
这里 re.findall(p.html) 用成 . 了 ,改成 , 逗号即可 即 :re.findall(p,html)
正确代码:
import urllib.request
import re
response = urllib.request.urlopen('https://tieba.baidu.com/p/6812722163')
html = response.read().decode('utf-8')
p = r'<img class="BDE_Image".*?src="[^"]*\.jpg".*?>'
imglist = re.findall(p,html)
for each in imglist:
print(each)
页:
[1]