【发布时间】:2009-12-03 22:59:53
【问题描述】:
我已准备好运行此代码,但在我想修复异常处理之前:
for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
bio = response.read()
item = re.search('(JD)(.*?)(\d+)', bio)
....
按照here 的建议,我添加了try...except,但现在如果页面无法打开,我会收到此错误:
bio = response.read()
NameError: name 'response' is not defined
所以程序继续执行。相反,我希望它返回 for 循环并尝试下一个 url。我尝试了break 而不是pass 但这结束了程序。有什么建议吗?
【问题讨论】: