python - 为什么python在某些网站使用urllib.request.urlopen时会返回错误
问题描述
当我在 python 3 中使用 url lib.requests 时,它适用于某些网站,但对于其他网站,它会返回错误:
import urllib.request
urllib.request.urlopen('wikipedia.org')
Traceback (most recent call last):
File "/Users/etudiant/Desktop/test.py", line 3, in <module>
urllib.request.urlopen('wikipedia.org')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 510, in open
req = Request(fullurl, data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 328, in __init__
self.full_url = url
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 354, in full_url
self._parse()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 383, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'wikipedia.org'
>>>
解决方案
推荐阅读
- python - 我正在尝试将一个大列表复制到 python 中的 excel 电子表格中
- mysql - 使用行值作为列?
- reactjs - 具有电子邮件功能的待办事项列表
- reactjs - 如何在 React 中使用 React Router 检测路由变化?
- bison - 在 Bison 中解析函数调用(例如 `exp '('exp ')'`):导致移位/减少错误(优先级问题)
- python - 在 Digitalocean 中标记快照
- android - Dagger2 插入图
- jenkins-pipeline - 如何在多个分支中保持多个 Jenkins 管道文件 (Jenkinsfile) 一致?
- c# - 如何将数据从文本框保存到 UWP 中的数据网格
- batch-file - 是否可以在 cmd 中使用操纵杆/游戏控制器输入?