|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
希望大家帮忙看一下,谢谢
import urllib.request
import re
def url_open(url):
headers = {
'Referer':'https://tieba.baidu.com/p/6214044057',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3676.400 QQBrowser/10.4.3469.400'
}
req=urllib.request.Request(url,headers=headers)
response=urllib.request.urlopen(req)
html=response.read().decode('utf-8')
return html
def get_img(html):
p=r'<img class=\\"BDE_Image\\" src=\\"([^"]+\.jpg)\\"'
img_list=re.findall(p,html)
for each in img_list:
print(each)
for each in img_list:
filename=each.split('/')[-1]
urllib.request.urlretrieve(each,filename)
if __name__=='__main__':
url='https://tieba.baidu.com/p/6214044057'
get_img(url_open(url))
代码如上
错误如下:
urllib.error.URLError: <urlopen error no host given>
爬取的连接是可以打印出来的,但是想要把图片下载下来就有错误了
|
|