html中的输出格式不正确

时间:2019-01-16 14:59:25

标签: python urllib2

下面的代码工作正常。

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

但是输出如下所示而不是单行显示。不确定网址长度问题

https://www.google.com/digitalworld/check_status/valid/next
,URL is good!
https://www.yahoo.com/digitalworld/check_status/valid/next
,URL is good!

请提供一些指导,以及如何引入同一行。

0 个答案:

没有答案