鱼C论坛

 找回密码
 立即注册
查看: 2105|回复: 14

[已解决]爬虫:我的urlopen为什么弹出来红色代码,求救

[复制链接]
发表于 2020-8-2 12:35:04 | 显示全部楼层 |阅读模式
1鱼币
按照甲鱼视频来的,
一模一样的代码,我的报错,求大神指导!
螢幕快照 2020-08-02 下午12.33.54.png
最佳答案
2020-8-2 12:35:05
本帖最后由 Twilight6 于 2020-8-2 12:54 编辑



试试这样运行,跳过下证书验证:
import ssl
import urllib.request
ssl._create_default_https_context = ssl._create_unverified_context
response = urllib.request.urlopen("http://www.fishc.com")

最佳答案

查看完整内容

试试这样运行,跳过下证书验证:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 12:35:05 | 显示全部楼层    本楼为最佳答案   
本帖最后由 Twilight6 于 2020-8-2 12:54 编辑



试试这样运行,跳过下证书验证:
import ssl
import urllib.request
ssl._create_default_https_context = ssl._create_unverified_context
response = urllib.request.urlopen("http://www.fishc.com")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 12:35:16 | 显示全部楼层
发代码……而且才悬赏 1 鱼币,太没诚意了吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 12:36:24 | 显示全部楼层
zltzlt 发表于 2020-8-2 12:35
发代码……而且才悬赏 1 鱼币,太没诚意了吧

我鱼B好少,哈哈,我多去赚点
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 12:38:36 | 显示全部楼层
qq13700416415 发表于 2020-8-2 12:36
我鱼B好少,哈哈,我多去赚点




普通求助帖都比你悬赏的高...所以说你还不如不设置悬赏,还不用浪费你鱼币

你的报错最后几行发上来,截图看不见,代码也顺便 copy 下发下吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 12:38:39 | 显示全部楼层
qq13700416415 发表于 2020-8-2 12:36
我鱼B好少,哈哈,我多去赚点

把你的代码传上来吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 12:44:21 | 显示全部楼层
>>> import urllib.request
>>> response = urllib.request.urlopen("http://www.fishc.com")
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 950, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1424, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    response = urllib.request.urlopen("http://www.fishc.com")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 563, in error
    result = self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 563, in error
    result = self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>
>>>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 12:45:15 | 显示全部楼层
代码已传,谢谢各位大佬
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 12:49:58 | 显示全部楼层
import urllib.request
response = urllib.request.urlopen("http://www.fishc.com")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 12:56:10 | 显示全部楼层
Twilight6 发表于 2020-8-2 12:35
试试这样运行,跳过下证书验证:

这是什么操作,小甲鱼没讲过。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 12:57:15 From FishC Mobile | 显示全部楼层
qq13700416415 发表于 2020-8-2 12:49

现在的鱼C论坛都支持 https 了,
但是代码里还是 http(历史遗留问题)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 13:08:21 | 显示全部楼层
Twilight6 发表于 2020-8-2 12:38
普通求助帖都比你悬赏的高...所以说你还不如不设置悬赏,还不用浪费你鱼币

你的报错 ...

我刚试了下,我每次要打开urlopen都得运行ssl,为啥这样子。。哭
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-2 13:32:00 | 显示全部楼层
qq13700416415 发表于 2020-8-2 13:08
我刚试了下,我每次要打开urlopen都得运行ssl,为啥这样子。。哭


我也不懂,我都不用加都可以打开的哈哈

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-2 14:49:50 | 显示全部楼层
Twilight6 发表于 2020-8-2 13:32
我也不懂,我都不用加都可以打开的哈哈

晕,难道我的是阉割版的python
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-8 22:00:23 From FishC Mobile | 显示全部楼层
试一下编辑器,新版本的用编辑器就可以
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-19 14:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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