鱼C论坛

 找回密码
 立即注册
查看: 939|回复: 3

图片下载,什么没,哪里错了

[复制链接]
发表于 2019-6-18 21:28:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import requests
  2. from lxml import etree
  3. headers = {
  4.     "User-Agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.3.2.17331"
  5.     "Referer""https://www.mzitu.com/tag/ugirls/"
  6. }

  7. response = requests.get("https://www.mzitu.com/tag/ugirls/",headers=headers)


  8. html = etree.HTML(response.text)
  9. src_list=html.xpath('//img[@class="lazy"]/@data-original')
  10. alt_list=html.xpath('//img[@class="lazy"]/@alt')

  11. for src,alt in zip(src_list, alt_list):
  12.     #print(src,alt)

  13.     response = requests.get(src,headers=headers)

  14.     fileName = alt+".jpg"
  15.     print("正在保:"+fileName)
  16.     with open(fileName,"wb") as f:
  17.         f.write(response.content)
复制代码


图片下载,什么没,哪里错了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-6-18 22:50:48 | 显示全部楼层
你想说是无法保存图片吗??
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-19 11:58:37 | 显示全部楼层
wongyusing 发表于 2019-6-18 22:50
你想说是无法保存图片吗??

恩,是的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-19 18:43:22 | 显示全部楼层


你检查一下你的headers,
少了一个逗号,少了一个冒号。

  1. import requests
  2. from lxml import etree
  3. headers = {
  4.     "User-Agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.3.2.17331",
  5.     "Referer":"https://www.mzitu.com/tag/ugirls/"
  6. }

  7. response = requests.get("https://www.mzitu.com/tag/ugirls/",headers=headers)
  8. print(response)

  9. html = etree.HTML(response.text)
  10. src_list=html.xpath('//img[@class="lazy"]/@data-original')
  11. alt_list=html.xpath('//img[@class="lazy"]/@alt')

  12. for src,alt in zip(src_list, alt_list):
  13.     #print(src,alt)

  14.     response = requests.get(src,headers=headers)
  15.     print(src)
  16.     print(response)
  17.     fileName = alt+".jpg"
  18.     print("正在保:"+fileName)
  19. #     with open(fileName,"wb") as f:
  20. #         f.write(response.content)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-16 10:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表