htm中的输出格式不正确

2024-10-05 13:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码工作正常。你知道吗

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!

能不能请一些导游和如何带进来的同行。你知道吗


Tags: httpscomformaturlisrequestcheckwww

热门问题