爬取图片时遇到了一点问题 请各位大佬指点
import urllib.requestimport os
import re
import random
def urlopen(url):
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6823.400 QQBrowser/10.3.3117.400')
proxies = ['124.152.32.140:53281', '163.125.157.53:8888', '163.125.157.49:8888']
proxy = random.choice(proxies)
proxy_support = urllib.request.ProxyHandler({'http':proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
html = urllib.request.urlopen(req)
html = html.read()
return html
def zhuyao(html):
p = r'<img class="lazy" src="(https://i.meizitu.net/thumbs/\d\d\d\d/\d\d/.+?.jpg)"'
tupian = re.findall(p,html)
for each in tupian:
wjm = each.split('/')[-1]
tp = urlopen(tupian)
with open(wjm,'wb') as f:
f.write(tp)
if __name__=='__main__':
url = 'https://www.mzitu.com/xinggan/'
os.mkdir('妹子图片')
os.chdir('妹子图片')
zhuyao(urlopen(url))
回溯(最近一次调用last):
文件“C: \用户桌面\ \ tx \妹子图片爬取。,第37行,在中
zhuyao (urlopen (url))
文件“C: \用户桌面\ \ tx \妹子图片爬取。26行,朱瑶
图皮人的= re.findall (p, html)
文件C: \ Python3.7.2 \ lib \再保险。findall中的第223行
返回_compile(模式、旗帜).findall(字符串)
类型错误:不能在类字节码对象上使用字符串模式
这是错误原因看不太懂 你这错误信息咋都变成中文了呢还不如英文(E文还能猜一猜是啥意思,这个中文反到是一点都不懂了——) 已经找到问题了解决了。。{:10_247:} {:5_109:} {:10_256:}{:10_256:}{:10_256:} {:5_95:} {:5_109:} {:10_300:} {:5_109:} {:10_243:} {:10_277:} {:10_277:} {:10_277:} {:10_277:}
页:
[1]