Closed. This question is off-topic. It is not currently accepting answers. Learn more。
想改进这个问题吗Update the question所以堆栈溢出的值小于aa>
我想知道,如果在访问网站时出现任何错误,urlopen是否有某种“全部捕获”代码会跳过for循环中的整个条目。
最佳答案
您可以使用try/except
块捕获异常:
# Python 3 example
from urllib.error import URLError, HTTPError
from urllib.request import urlopen
for entry in entries:
try:
data = urlopen(...)
except URLError, HTTPError:
print("Something bad happened")
else:
# Process data get from the URL opened
# If an exception has been catch, you won't
# enter in this else block
10-06 01:10