import requests
import urllib
from bs4 import BeautifulSoup
html = requests.get("http://www.nipic.com/index.html")
#print(html.text)
soup = BeautifulSoup(html.text,"html.parser")
img = soup.find_all("img")#得到一个image数组
i=0
for x in img:
#print(x.get('src'))
src = x.get('src')
file_path= '/users/nick/Documents/data/'
file_name = '%s.jpg' % i
urllib.request.urlretrieve(src, file_path + file_name)
i += 1
python爬虫保存网页中图片
最新推荐文章于 2024-05-02 21:47:38 发布