鱼C论坛

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

爬虫报错

[复制链接]
发表于 2020-3-13 15:24:24 | 显示全部楼层 |阅读模式

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

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

x
跟着小甲鱼的视频敲的代码,但是在运行时报错,图片也没下载下来,请问这是什么原因导致的?
代码:
import urllib.request

response = urllib.request.urlopen('http://placekitten.com/g/200/300')
cat_img = response.read()

with open('cat_200_300.jpg','wb') as f:
    f.write(cat_img)import urllib.request
报错:
Traceback (most recent call last):
  File "C:\Users\16285\Desktop\download.py", line 3, in <module>
    response = urllib.request.urlopen('http://placekitten.com/g/200/300')
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1348, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1323, in do_open
    r = h.getresponse()
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1322, in getresponse
    response.begin()
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:\Users\16285\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 272, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-13 18:52:21 From FishC Mobile | 显示全部楼层
连headers都不伪装,不被痛打才怪
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-13 22:55:21 | 显示全部楼层
wp231957 发表于 2020-3-13 18:52
连headers都不伪装,不被痛打才怪

能详细说一下嘛?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-14 06:55:57 From FishC Mobile | 显示全部楼层
贰柒 发表于 2020-3-13 22:55
能详细说一下嘛?

https://fishc.com.cn/forum.php?mod=viewthread&tid=157994
我不用urllib库,所以你对付看一下,主要看后面爬虫部分即可
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-12 04:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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