鱼C论坛

 找回密码
 立即注册
查看: 1460|回复: 1

[已解决]爬虫出错了

[复制链接]
发表于 2020-7-26 18:49:04 | 显示全部楼层 |阅读模式

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

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

x
这是错误
Traceback (most recent call last):
  File "F:\lib\urllib\request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "F:\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "F:\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "F:\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "F:\lib\http\client.py", line 1010, in _send_output
    self.send(msg)
  File "F:\lib\http\client.py", line 950, in send
    self.connect()
  File "F:\lib\http\client.py", line 921, in connect
    self.sock = self._create_connection(
  File "F:\lib\socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "F:\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:/p55.py", line 3, in <module>
    p=u.urlopen(r)
  File "F:\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "F:\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "F:\lib\urllib\request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "F:\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "F:\lib\urllib\request.py", line 1379, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "F:\lib\urllib\request.py", line 1353, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo failed>
这是源代码
import urllib.request as u
r=u.Request('http://plaeckitten.com/g/500/600')
p=u.urlopen(r)
c=p.read()
with open("cat.jpg",'wb') as f:
    f.write(c)
哪里出错了?
最佳答案
2020-7-27 08:41:15
网址拼错了,http://plaeckitten.com/g/500/600,正确代码:
import urllib.request as u

r = u.Request('http://placekitten.com/g/500/600')
p = u.urlopen(r)
c = p.read()
with open("cat.jpg", 'wb') as f:
    f.write(c)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-27 08:41:15 | 显示全部楼层    本楼为最佳答案   
网址拼错了,http://plaeckitten.com/g/500/600,正确代码:
import urllib.request as u

r = u.Request('http://placekitten.com/g/500/600')
p = u.urlopen(r)
c = p.read()
with open("cat.jpg", 'wb') as f:
    f.write(c)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-11 11:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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