我试图从“www.money.usnews.com”中获取数据,但我始终得到这样的时间错误,即:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host has failed to
respond.
这是我的代码:(我包括了一个不同的网站作为测试用例,它是有效的。我是新的网页抓取。我应该怎么做
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
try:
html = urlopen('https://money.usnews.com')
# html = urlopen('http://www.timeanddate.com/weather/usa/los-angeles')
except HTTPError as e:
print(e)
except URLError as e:
print("No server")
except ValueError as e:
print("NULL ")
else:
print("b")
bs = BeautifulSoup(html.read(), 'html.parser')
print(bs.h1)
目前没有回答
相关问题 更多 >
编程相关推荐