python - 我可能做错了什么?尝试从该特定站点抓取数据时出现超时错误?
问题描述
我试图从“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)
解决方案
推荐阅读
- xcode - 离子电容随机出错
- python - Selenium,For循环:当页面上没有特定元素时如何使循环持续
- cloud-foundry - CloudFoundry 用户提供的服务与环境变量
- vue.js - vue 将字符串渲染为已经存在的组件
- groovy - Groovy 脚本:没有方法签名
- c - 数组 C 中数字的总和和平均值
- r - 编写脚本以忽略在 r 中找不到的对象
- angular - $q.allsettle 等价于 Angular 2 捕捉所有成功和失败
- automated-tests - 如何在发布管道视图中查看正在进行的测试的测试结果?
- css - WP Bakery 选项卡动画覆盖