import re
from bs4 import BeautifulSoup
import requests
headers={'User-agent':'Mozilla/5.0(Linux:Android 6.0;Nexus 5 Build/MRA58M)''ApplewebKit/537.36(KHTML,like Gecko)''Chrome/104.0.5112.81'}
url='' ###填写需要爬取的图片url
res=requests.get(url,headers=headers)
soup=BeautifulSoup(res.text,'html.parser')
img_link=[]
for i in soup.find_all("img"):
if i.get('src')!=None:
#####构建爬取图片的url地址
Picture='https:'+i.get('src')
responseimge = requests.get(Picture)
file_name = Picture.split('/')[-1]
with open('%s' % (file_name), 'wb', ) as f:
f.write(responseimge.content)
else:
pass
标签:Picture,get,python,headers,url,简单,import,requests,图片
From: https://blog.51cto.com/u_16056808/6538943