Python3-requests-xpath-抓取圖片並保存
一(來自別人的)
import requests
from lxml import etree
j=0
#設置的翻頁
for i in range(0,2):
r=requests.get('https://book.douban.com/tag/%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C?'+'start=%d&type=T'%i*20).content
books=etree.HTML(r)
抓取圖片的鏈接 通過xpath
imgs=books.xpath('//*[@id="subject_list"]/ul/li/div[1]/a/img/@src', stream=True)
#保存位置
path = "E:/IMG/"
for img in imgs:
j=j+1
#------------位置+保存的名稱(名稱此處是遞增的 j)
with open(path+str(j)+'.jpg', 'wb') as fd:
picture=requests.get(img).content
fd.write(picture)
原文鏈接–https://blog.csdn.net/weixin_39777626/article/details/79300856
方法二
import urllib
urllib.urlretrieve('圖片鏈接http://', 'f:/自己的本地地址.jpg')