点击网页到你想下载图片的网址
链接: 跳转.
按F12或者点击右键检查
获得图片地址
找到原图下载地址
链接: 跳转.
查看一下图片地址
再点击下面的查看原图
找到原图地址
话不多说,上代码
import requests
from lxml import etree
from pathlib import Path
#获取电脑桌面地址
path = Path.home()
path1 = str(path / 'Desktop/')
#图片主地址
#//img.ivsky.com/img/tupian/t/202104/08/gouzai.jpg
#图片主页面
url="https://www.ivsky.com/tupian/gouzai_v66492/"
#headers是用来防止被识别的
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 UBrowser/6.1.2107.204 Safari/537.36'}
iid=requests.get(url,headers=headers)
getid = etree.HTML(iid.text)
#获得所有的图片地址
allid=getid.xpath("//*[@class='left']/ul[1]/li/p[1]/a[1]/@href")
#拼接得到真正图片地址
for i in allid:
ul="https://www.ivsky.com/"+i
ulid= requests.get(ul, headers=headers)
# 获得图片的图片地址
getulid = etree.HTML(ulid.text)
ullid = getulid.xpath("//*[@id='pic_con']/div[1]/img/@src")
for i1 in ullid:
uld="https:"+i1
#得到网页图片地址
# https://img-pre.ivsky.com/img/tupian/pre/202104/08/gouzai.jpg
#查看原图的地址
# https://img-picdown.ivsky.com/img/tupian/pic/202104/08/gouzai.jpg
#替换
ur=str(uld).replace("img-pre",'img-picdown').replace("pre","pic")
#获得末尾
last=str(uld).split("/")[-1]
down = requests.get(ur, headers=headers)
with open(path1 + "\\"+last, "wb")as f:
f.write(down.content)
#一秒延迟下载
import time
time.sleep(1)