这个爬取妹子图的程序已经完成了,也可以运行,但是下载不下来图片,求帮忙!!!
import urllib.requestimport re
def open_url(url):
req = urllib.request.Request(url)
req.add_header = ('User-Agent','Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36')
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
return html
def get_image(html):
p = r'<img class="BDE_Image" pic_type="\d?\d?\d" width="\d?\d?\d" height="\d?\d?\d" src="([^"]+\.jpg)"'
imglist = re.findall(p,html)
#测试是否获取数据
'''
for each in imglist:
print(each)
'''
for each in imglist:
filename = each.split("/")[-1]
urllib.request.urlretrieve(each,filename,None)
if __name__ == '__main__':
url = "https://tieba.baidu.com/p/4192700628"
get_image(open_url(url))
url = "https://tieba.baidu.com/p/4192700628" 听说百度最近加了个什么玩意,爬不了了哈哈 我直接有你的代码可以下载
suchocolate 发表于 2020-7-19 17:02
我直接有你的代码可以下载
谢谢,不知道为什么把shell放在桌面就可以,放在桌面的文件夹里在桌面运行就不行
页:
[1]