web抓取时,远程主机错误强制关闭了现有连接

2024-10-06 06:57:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python beautifulsoup和urllib.请求从以下网站收集天气数据-

http://www.wunderground.com/history/airport/CYTZ/

以下是获取网页的代码

^{pr2}$

我意外地保留了一些数据,但我需要的结果是-

URLError: <urlopen error [WinError 10054] An existing connection was forcibly closed by the remote host>  

每次运行程序时,结果的数量都会有所不同。有没有一种特殊的方法可以阻止这种情况的发生并在一次运行中提取所有结果?谢谢


Tags: 数据代码comhttp网页网站wwwurllib