采用requests
库和beautiful soup
库
import requests
from bs4 import BeautifulSoup
# 站点信息
weburl = r"http://www.meizitu.com"
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/49.0.2623.75 Safari/537.36'}
page = requests.get(weburl,headers = headers)
soup = BeautifulSoup(page.text,"html.parser")
# 保存图片
num_img = 0
for link in soup.find_all('img'):
img_url = link.get('src')
r = requests.get(img_url)
num_img += 1
img_name = 'd:\pic\meizitu' + str(num_img) + '.jpg'
with open(img_name,'wb') as f:
f.write(r.content)
print('picture ' + str(num_img))
print('图片下载完成')
网友评论