我正在尝试列出来自csv文件的网址,以查看他们的HTTP代码是什么。这就是我到目前为止所得到的:
import urllib.request, urllib.error
url = ['http://www.10vibes.info'
'http://www.10vibes.info']
try:
conn = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
print(e.code)
except urllib.error.URLError as e:
print('URLError')
else:
print('good')
答案 0 :(得分:0)
将url作为字符串传递如下:
import urllib.request, urllib.error
url = ['http://www.10vibes.info'
'http://www.10vibes.info']
for my_url in url:
try:
conn = urllib.request.urlopen(my_url)
except urllib.error.HTTPError as e:
# Return code error (e.g. 404, 501, ...)
# ...
print(e.code)
pass
except urllib.error.URLError as e:
# Not an HTTP-specific error (e.g. connection refused)
# ...
print('URLError')
pass
print('good')