【发布时间】:2016-07-08 20:56:40
【问题描述】:
-
我知道网址检查有多个问题。我很新 python所以试图从多个帖子中理解并搜索 新图书馆也有帮助。我正在努力为以下点工作 内部网站和外部网站。 :
Status Code Status Description Response Length Time Taken Websites are like ,, www.xyz.com , www.abc.log , www.abc.com/xxx/login.html and more combinations. Below is the初始代码..
import socket from urllib2 import urlopen, URLError, HTTPError import urllib socket.setdefaulttimeout( 23 ) # timeout in seconds #print "---------URL----------", " ---Status Code---" url='https://www.google.com' try : response = urlopen( url ) except HTTPError, e: print 'The server couldn\'t fulfill the request. Reason:', str(e.code) #Want to get code for that but its not showing except URLError, e: print 'We failed to reach a server. Reason:', str(e.reasonse) #Want to get code for that but its not showing else : code=urllib.urlopen(url).getcode() **#here getcode is working print url,"-------->", code #print 'got response!' 我想先检查网站是否存在。然后会去 其余检查如上所述。如何组织这个工作 500 多个网址的所有上述要点。我需要从txt文件导入吗 ?还有一点我已经看到,如果 www.xyx.com 正在工作并且 www.xyz.com/lmn.html 不存在,它仍然显示 200 。
【问题讨论】:
标签: python python-2.7 python-3.x url http-headers