首页 > 解决方案 > 我可能做错了什么?尝试从该特定站点抓取数据时出现超时错误?

问题描述

我试图从“www.money.usnews.com”中抓取数据,但我一直收到这个 TimeoutError,上面写着:

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)

标签: pythonwebweb-scraping

解决方案


推荐阅读