ConnectionError:HTTPConnectionPool Python Web抓取

2024-09-30 08:28:20 发布

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

我不熟悉使用python进行web清理,在开始使用时遇到了一些困难。我已经安装了所有正确的imnports,但仍然收到以下错误:

ConnectionError:HTTPConnectionPool(host='econpy.pythonanywhere.com网站',port=80):超出了最大重试次数,url:/ex/001.html(由NewConnectionError(':无法建立新连接:[Errno 10060]连接尝试失败,因为连接方在一段时间后没有正确响应,或建立的连接失败,因为连接的主机未能响应',)

我在googlechrome中检查了我的代理设置,并选中了“通过代理连接使用http1.1”。有什么想法吗?在

下面是我正在尝试的代码: 从lxml导入html 导入请求

page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.content)

#This will create a list of buyers:
buyers = tree.xpath('//div[@title="buyer-name"]/text()')
#This will create a list of prices
prices = tree.xpath('//span[@class="item-price"]/text()')

print 'Buyers: ', buyers
print 'Prices: ', prices

Tags: ofcomtree代理htmlcreatepagethis

热门问题