下面的代码工作正常。你知道吗
from urllib2 import Request, urlopen, URLError
url = ['https://www.google.com/digitalworld/check_status/valid/next','https://www.yahoo.com/digitalworld/check_status/valid/next']
for i in url:
req = Request(i)
try:
response = urlopen(i)
except URLError, e:
if hasattr(e, 'reason'):
st = 'We failed to reach a server. Reason: ', e.reason
ck2 = '{0},{1}'.format(i,st)
print ck2
elif hasattr(e, 'code'):
st1 = 'The server couldn\'t fulfill the request. Error code: ', e.code
ck1 = '{0},{1}'.format(i,st1)
print ck1
else:
st2 = 'URL is good!'
ck = '{0},{1}'.format(i,st2)
print ck
但是输出如下,不是一行。不确定URL长度问题
https://www.google.com/digitalworld/check_status/valid/next
,URL is good!
https://www.yahoo.com/digitalworld/check_status/valid/next
,URL is good!
能不能请一些导游和如何带进来的同行。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐