lxml在repl.it上的请求 [英] lxml requests on repl.it

查看:97
本文介绍了lxml在repl.it上的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 Replit 上的lxml请求,但我不明白为什么它不是在职的.该程序直到最大重试次数才停止运行,在此我得到此错误:

回溯(最近通话最近): 文件"python",第6行,在 requests.exceptions.ConnectionError:HTTPConnectionPool(host ='www.presidency.ucsb.edu',port = 80):URL超过了最大重试次数:/ws/index.php?pid = 29400.html(由NewConnectionError(':无法建立新的连接:[Errno -2]名称或服务未知',))

我的代码非常简单:

from lxml import html
import requests

url = 'http://www.presidency.ucsb.edu/ws/index.php?pid=29400.html'

r = requests.get(url)
tree = html.fromstring(r.content)

text = tree.xpath('//span[@class="displaytext"]/text()')

print(text)

如何运行此程序?我正在尝试获取该网站的内容,该网站位于"displaytext"跨度类中.我一直在使用此Python指南作为参考.

Python 3.5版

解决方案

我是Repl.it的工程师,这是我们平台的限制.我们目前不允许传出网络请求.

I'm trying lxml requests on Replit and I don't understand why it isn't working. The program doesn't stop running until the max retries, where I get this error:

Traceback (most recent call last): File "python", line 6, in requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.presidency.ucsb.edu', port=80): Max retries exceeded with url: /ws/index.php?pid=29400.html (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))

my code is quite straightforward:

from lxml import html
import requests

url = 'http://www.presidency.ucsb.edu/ws/index.php?pid=29400.html'

r = requests.get(url)
tree = html.fromstring(r.content)

text = tree.xpath('//span[@class="displaytext"]/text()')

print(text)

How can I get this to run? I'm trying to get the content of that website, located in the "displaytext" span class. I've been using this Python guide for reference.

Python version 3.5

解决方案

I'm an engineer at Repl.it and this is a limitation with our platform. We don't currently allow outgoing network requests.

这篇关于lxml在repl.it上的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆