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>)
新聞熱點
疑難解答