我正在尝试捕获错误 60 并继续执行我的脚本,这就是我目前正在做的事情:
import urllib2
import csv
from bs4 import BeautifulSoup
matcher = csv.reader(open('matcher.csv', "rb" ))
for i in matcher:
url = i[1]
if len(list(url)) > 0:
print url
try:
soup = BeautifulSoup(urllib2.urlopen(url,timeout=10))
except urllib2.URLError, e:
print ("There was an error: %r" % e)
它返回这个:
回溯(最后一次调用):文件“debug.py”,第 13 行,在 soup = BeautifulSoup(urllib2.urlopen(url,timeout=10)) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib /python2.7/urllib2.py”,第 126 行,在 urlopen 返回 _opener.open(url, data, timeout) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py ",第 400 行,打开响应 = self._open(req, data) 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",第 418 行,在 _open '_open ', req) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第 378 行,在 _call_chain 结果 = func(*args) 文件“/Library/Frameworks/Python .framework/Versions/2.7/lib/python2.7/urllib2.py”,第 1207 行,在 http_open 返回 self.do_open(httplib.HTTPConnection, req) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第 1180 行,在 do_open r = h.getresponse( buffering=True)文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py”,第1030行,在getresponse response.begin()文件“/Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/httplib.py”,第 407 行,开始版本,状态,原因 = self._read_status() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2 .7/httplib.py”,第 365 行,在 _read_status 行 = self.fp.readline() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 447 行, 在 readline 数据 = self._sock.recv(self._rbufsize) socket.timeout: 超时
我将如何捕获此错误并“继续”?