import requests
from bs4 import BeautifulSoup
url='http://spiderbuf.cn/trainingbox?level=5'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'}
dataSource = requests.get(url,headers=headers)
data = dataSource.text
soup = BeautifulSoup(data,'lxml')
imgSource = soup.find_all(name ='div',attrs={'class','col-sm-4'})
for imgs in imgSource:
imgs = imgs.select('img')
for href_img in imgs:
urls='http://spiderbuf.cn'
urls+=href_img.attrs['src']
img_data = requests.get(urls,headers=headers)
with open('\\images','wb') as fp:
fp.write(img_data.content)
open时指定绝对路径,win下如'd:/images',linux
下如'~/images'