我使用Scrapy框架来抓取数据。如果我的爬虫遇到500错误,它将被中断。因此,我需要在解析web内容之前检查可用的链接。
有什么方法可以解决我的问题吗?
非常感谢。
发布于 2012-09-23 14:52:54
如果url存在,可以使用urllib的()方法检查:
import urllib
import sys
webFile = urllib.urlopen('http://www.some.url/some/file')
returnCode = webFile.getCode()
if returnCode == 500:
sys.exit()
# in other case do something.
https://stackoverflow.com/questions/12200715
复制相似问题