基本信息
源码名称:校花网图片自动下载
源码大小:0.82KB
文件格式:.py
开发语言:Python
更新时间:2021-06-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
图片网址:http://www.gaokao.com/gkpic/
存储路径:D:\校花(若不存在,则自动创建文件夹)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
}
url = 'http://www.gaokao.com/gkpic/'
request = urllib.request.Request(url,headers=headers)
response = urllib.request.urlopen(request)
html = etree.HTML(response.read().decode('gbk'))
results = html.xpath('//div[@id="imgall"]/a//img')
for result in results:
down_load = result.attrib.get('src')
# photo_name = str(down_load).rsplit('/',1)[1]
photo_name = result.attrib.get('alt')
urlretrieve(down_load, target_dir '/' photo_name '.jpg')
print(photo_name)