[英]Getting an error when using urllib.request.urlopen() on Python 3.2.1
[英]Why does python return an error when using urllib.request.urlopen for certain websites
當我在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'
>>>
嘗試這個 :
import urllib.request
urllib.request.urlopen('https://www.wikipedia.org/')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.