您好,登錄后才能下訂單哦!
由于python3 對StringIO 集成到io 模塊中了,所有python3 import StringIO 改成了 import io,pycurl.Curl() 初始化對象C ,其 屬性WRITEFUNCTION 要求傳遞參數是byte,b.write 需要初始化成io.BytesIO()
#!/bin/env pyhon3
import pycurl
import io
def check(urls):
dict_data={}
#if url not in errorurl:
url = 'http://' + str(urls)
dict_data['url']=url
c = pycurl.Curl()
c.setopt(pycurl.CONNECTTIMEOUT,5)
c.setopt(pycurl.TIMEOUT,5)
c.setopt(pycurl.NOPROGRESS,1)
c.setopt(pycurl.FORBID_REUSE,1)
c.setopt(pycurl.MAXREDIRS,3)
c.setopt(pycurl.DNS_CACHE_TIMEOUT,30)
c.setopt(c.URL, url)
try:
b = io.BytesIO()
c.setopt(c.WRITEFUNCTION, b.write)
c.perform()
HTTP_CODE = c.getinfo(pycurl.HTTP_CODE) #HTTP狀態碼
dict_data['HTTP狀態碼'] = HTTP_CODE
DNS_TIME = c.getinfo(c.NAMELOOKUP_TIME) 1000 #DNS消耗時間
dict_data['DNS消耗時間'] = DNS_TIME
CONNECT_TIME = c.getinfo(c.CONNECT_TIME) 1000 #建連消耗時間
dict_data['建連消耗時間'] = CONNECT_TIME
PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME) 1000 #建連到準備傳輸消耗
dict_data['建連到準備傳輸消耗'] = PRETRANSFER_TIME
STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME) 1000 #建連到傳輸消耗
dict_data['建連到傳輸消耗'] = STARTTRANSFER_TIME
TOTAL_TIME = c.getinfo(c.TOTAL_TIME) * 1000 #傳輸結束消耗時間
dict_data['傳輸結束消耗時間'] = TOTAL_TIME
SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD) #平均下載速度
dict_data['平均下載速度'] = SPEED_DOWNLOAD
b.close()
c.close()
except pycurl.error:
pass
#errno, errstr = error
#print 'An error occurred: ', errstr
for var in dict_data.keys():
print(var,':',dict_data[var])
website=input('請輸入檢測站點域名:如www.baidu.com')
check(website)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。