在跟随youtube上的网络抓取教程之后,由于网址而出现此错误。它在Spyder中运行正常,但是当我尝试在命令提示符中运行它时,一切都变得混乱了。
我从这里尝试了各种答案(quote()将“:”转换为“%3A”以及其他一些类似urlencode()的答案),但是它没有用。也许我不知道如何使它们工作。
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
#from urllib.parse import quote
my_url = 'https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20card'
# opening connection, grabbing information and closing connection
uClient = uReq(my_url)
这是错误消息-
Traceback (most recent call last):
File "my_first_webscrape.py", line 8, in <module>
uClient = uReq(my_url)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 548, in _open
'unknown_open', req)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1387, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>