一聚教程网 >Php教程>>python >
Python中为feedparser设置超时时间教程
www.111cn.net 编辑:swteen 来源:转载
python解析RSS(feedparser)支持几乎所有的rss解析了,下文我们重点是介绍feedparser设置超时时间了,有兴趣的一起来看看。
python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设置一个超时时间。
可是feedparser并没有提供这(www.111cn.net)个功能,只好采用其他方法了,具体办法请参看feedparser项目的issue221。
其实也很简单,按照上面文档的说明
developers have had the ability to set a global timeout for over seven years by importing the socket library and setting the timeout in this way:
import socket
socket.setdefaulttimeout(<timeout in floating seconds>)
from:[url]http://www.111cn.net/phper/python/66849.htm[/url]
Python中为feedparser设置超时时间教程
www.111cn.net 编辑:swteen 来源:转载
python解析RSS(feedparser)支持几乎所有的rss解析了,下文我们重点是介绍feedparser设置超时时间了,有兴趣的一起来看看。
python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设置一个超时时间。
可是feedparser并没有提供这(www.111cn.net)个功能,只好采用其他方法了,具体办法请参看feedparser项目的issue221。
其实也很简单,按照上面文档的说明
developers have had the ability to set a global timeout for over seven years by importing the socket library and setting the timeout in this way:
import socket
socket.setdefaulttimeout(<timeout in floating seconds>)
from:[url]http://www.111cn.net/phper/python/66849.htm[/url]
详解Python中为feedparser设置超时时间的方法
本文详细介绍了如何在Python中通过feedparser模块解析RSS,并着重讲解了如何为feedparser设置超时时间以解决遇到的badurl堵塞问题。通过导入socket库并设置timeout参数,开发者能够实现对feedparser的超时控制。
517

被折叠的 条评论
为什么被折叠?



