[英]Does any python http lib can output the spent time for each step
I want to log some performance information for a python web spider project. 我想为python网络蜘蛛项目记录一些性能信息。 with curl , I can use following command to get the spent time info. 使用curl,我可以使用以下命令来获取花费的时间信息。
curl_format='{
"time_namelookup": %{time_namelookup},
"time_connect": %{time_connect},
"time_appconnect": %{time_appconnect},
"time_pretransfer": %{time_pretransfer},
"time_redirect": %{time_redirect},
"time_starttransfer": %{time_starttransfer},
"time_total": %{time_total}
}'
exec curl -w "$curl_format" -o /dev/null -s http://www.google.com
If I don't call "curl" command in python code, is there any other python lib/module can get these info? 如果我没有在python代码中调用“ curl”命令,是否还有其他python lib / module可以获取这些信息?
PyCurl can do this PyCurl可以做到这一点
import pycurl
c = pycurl.Curl()
c.setopt(c.URL, 'http://www.google.com')
c.setopt(c.NOBODY, 1)
c.perform()
print('time_connect: {0}'.format(c.getinfo(c.CONNECT_TIME)))
print('time_pretransfer: {0}'.format(c.getinfo(c.PRETRANSFER_TIME)))
print('time_redirect: {0}'.format(c.getinfo(c.REDIRECT_TIME)))
print('time_starttransfer: {0}'.format(c.getinfo(c.STARTTRANSFER_TIME)))
print('time_total: {0}'.format(c.getinfo(c.TOTAL_TIME)))
c.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.