使用 python lxml 设置解析网页的超时
我正在使用 python lxml 库来解析 html 页面:
import lxml.html
# this might run indefinitely
page = lxml.html.parse('http://stackoverflow.com/')
有没有办法设置解析超时?
I am using python lxml library to parse html pages:
import lxml.html
# this might run indefinitely
page = lxml.html.parse('http://stackoverflow.com/')
Is there any way to set timeout for parsing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来使用 urllib.urlopen 作为开启器,但最简单的方法只是修改套接字处理程序的默认超时。
当然,这是一个快速而肮脏的解决方案。
It looks to be using
urllib.urlopen
as the opener, but the easiest way to do this would just to modify the default timeout for the socket handler.Of course this is a quick-and-dirty solution.