Python中为feedparser设置超时时间避免堵塞

yipeiwu_com6年前Python基础

python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设置一个超时时间。

可是feedparser并没有提供这个功能,只好采用其他方法了,具体办法请参看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>)

相关文章

python正则实现提取电话功能

本文实例为大家分享了python正则提取电话的具体代码,供大家参考,具体内容如下 主要用到正则 import re import xlrd def is_number(s):#是...

Python中list查询及所需时间计算操作示例

本文实例讲述了Python中list查询及所需时间计算操作。分享给大家供大家参考,具体如下: # -*-coding=utf-8 -*- #! python2 #filename:...

Python判断对象是否为文件对象(file object)的三种方法示例

文件操作是开发中经常遇到的场景,那么如何判断一个对象是文件对象呢?下面我们总结了3种常见的方法。 方法1:比较类型 第一种方法,就是判断对象的type是否为file >>...

解决webdriver.Chrome()报错:Message:'chromedriver' executable needs to be in Path

解决webdriver.Chrome()报错:Message:'chromedriver' executable needs to be in Path

'chromedriver' executable needs to be in Path 声明:本人萌新,刚学python不久记录一下自己的坑,发出来若能帮助到一些人尽早解决问题那便是...

python的构建工具setup.py的方法使用示例

python的构建工具setup.py的方法使用示例

本文介绍了python的构建工具setup.py,分享个大家,具体如下: 一、构建工具setup.py的应用场景 在安装python的相关模块和库时,我们一般使用“pip install...