Python 官方文档:入门教程 => 点击学习
由于python3 对Stringio 集成到io 模块中了,所有python3 import StringIO 改成了 import io,pycurl.Curl() 初始化对象C ,其 属性WRITEFUNCTION 要求传递参数是by
由于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)
--结束END--
本文标题: python3 通过 pycurl 检测
本文链接: https://lsjlt.com/news/192214.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0