python:获取访问访问时的响应时间
import time
import os
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait def get_clear_browsing_button(driver):
"""Find the "CLEAR BROWSING BUTTON" on the Chrome settings page."""
return driver.find_element_by_css_selector('* /deep/ #clearBrowsingDataConfirm') def clear_cache(driver, timeout=60):
"""Clear the cookies and cache for the ChromeDriver instance."""
# navigate to the settings page
driver.get('chrome://settings/clearBrowserData')
# wait for the button to appear
wait = WebDriverWait(driver, timeout)
wait.until(get_clear_browsing_button)
# click the button to clear the cache
get_clear_browsing_button(driver).click()
# wait for the button to be gone before returning
wait.until_not(get_clear_browsing_button) """
Use Selenium to Measure Web Timing
Performance Timing Events flow
navigationStart -> redirectStart -> redirectEnd -> fetchStart -> domainLookupStart -> domainLookupEnd
-> connectStart -> connectEnd -> requestStart -> responseStart -> responseEnd
-> domLoading -> domInteractive -> domContentLoaded -> domComplete -> loadEventStart -> loadEventEnd
https://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute
"""
def access_url(driver, url):
# clear_cache(driver)
driver.get(url)
navigation_start = driver.execute_script("return window.performance.timing.navigationStart")
load_end = driver.execute_script("return window.performance.timing.loadEventEnd")
return load_end - navigation_start; def test_url(driver, log_file, url, count):
data = []
for idx in range(count):
load_time = access_url(driver, url)
data.append(load_time)
soted_data = sorted(data)
min_val = soted_data[0]
mid_val = soted_data[count//2]
max_val = soted_data[-1]
avg_val = sum(data)/count log_file.write("test '%s' %d times min:%d mid:%d max:%d avg:%d data:%s\n" %
(url, count, min_val, mid_val, max_val, avg_val, str(data))) if __name__ == "__main__":
pwd_path = os.getcwd()
options = webdriver.chrome.options.Options()
#options.add_argument("--load-extension=" + os.path.join(pwd_path, "Adblock-Plus_v1.13.4"))
options.add_argument("--user-data-dir=" + os.path.join(pwd_path, "chrome_user_data"))
options.add_argument("--start-maximized")
#options.add_extension(os.path.join(pwd_path, "AdBlock_v3.22.1.crx"))
options.add_extension(os.path.join(pwd_path, "Adblock-Plus_v1.13.4.crx"))
driver = webdriver.Chrome(chrome_options=options) url_list = [
#"北京时间",
"https://www.btime.com",
"https://www.btime.com/sports",
"https://item.btime.com/m_2s21ridqq1l",
#"军事头条",
"http://www.tiexue.net/",
"http://bbs.tiexue.net/post2_12837139_1.html",
"http://www.tiexue.net/ShowPicClass_1485_1.html",
]
test_times = 20; with open('chrome_Adblock-Plus.txt', 'w') as log_file:
for url in url_list:
test_url(driver, log_file, url, test_times) driver.close()
python:获取访问访问时的响应时间的更多相关文章
- Python类属性访问的魔法方法
Python类属性访问的魔法方法: 1. __getattr__(self, name)- 定义当用户试图获取一个不存在的属性时的行为 2. __getattribute__(self, name)- ...
- 第14.7节 Python模拟浏览器访问实现http报文体压缩传输
一. 引言 在<第14.6节 Python模拟浏览器访问网页的实现代码>介绍了使用urllib包的request模块访问网页的方法.但上节特别说明http报文头Accept-Encodin ...
- Python+Selenium学习--访问连接
场景 web UI测试里最简单也是最基本的事情就是访问1个链接了. 在python的webdrive中,访问url时应该使用get方法. 代码 #!/usr/bin/env python # -*- ...
- Nginx反向代理+Tomcat+Springmvc获取用户访问ip
Nginx+Tomcat+Springmvc获取用户访问ip 1.Nginx反向代理 修改Nginx配置文件 location / { ***********之前代码*******; proxy_se ...
- python学习(22) 访问数据库
原文链接:http://www.limerence2017.com/2018/01/11/python22/ 本文介绍python如何使用数据库方面的知识. SQLite SQLite是一种嵌入式数据 ...
- python基础===成员访问__len__()和__getitem__()
class A: def __init__(self,*args): self.name = arg pass def __len__(self): return len(self.name) a = ...
- 第14.4节 使用IE浏览器获取网站访问的http信息
上节<第14.3节 使用google浏览器获取网站访问的http信息>中介绍了使用Google浏览器怎么获取网站访问的http相关报文信息,本节介绍IE浏览器中怎么获取相关信息.以上节为基 ...
- FireFox每次访问页面时检查最新版本
FireFox每次访问页面时检查最新版本 浏览器都有自己的缓存机制,作为开发人员,每次js的修改都要清空缓存,显然很不方便.而firefox并没有提供ie那样的设置. 下面的方法就可以非常方便的设置f ...
- Linux分析日志获取最多访问的前10个IP
原文地址:http://xuqq999.blog.51cto.com/3357083/774714 apache日志分析可以获得很多有用的信息,现在来试试最基本的,获取最多访问的前10个IP地址及访问 ...
- 访问网页时提示的503错误信息在IIS中怎么设置
访问网页时提示的503错误信息在IIS中怎么设置 503是一种常见的HTTP状态码,出现此提示信息的原因是由于临时的服务器维护或者过载,服务器当前无法处理请求则导致了访问网页时出现了503错误.那么当 ...
随机推荐
- python re 实例
#!/usr/bin/env python#_*_coding:utf-8_*_ import reimport timeimport jsonimport MySQLdbimport context ...
- 《LOST》 电视
还没看正剧,所以转来帮助看电视 从起源到终点:<LOST>剧情全解析(一) 此文是LOST完结之后的剧情解析,剧透,慎入 从起源到终点:<LOST>剧情全解析(一) 转 ...
- Web API 令牌(秘钥是双方约定的,并不在网络连接上传输)
http://blog.csdn.net/qq289523052/article/details/47750021 秘钥是双方约定的,并不在网络连接上传输 Web API数据传输加密 2015-08- ...
- 【转】CSR蓝牙驱动程序引起的Win7奇怪问题
https://www.yanning.wang/archives/299.html @echo off title 恢复系统 REM 变量初始化 rem CSR路径 set CSRPath=&quo ...
- plsql 创建表空间、用户、赋予权限
plsql 创建表空间.用户.赋予权限 --用户名:testuser --密码:bzhs!*6 --1.创建表空间--用SYSTEM用户登陆数据库,执行下面语句创建表空间CREATE TABLESPA ...
- Delegate event 委托事件---两个From窗体使用委托事件
窗体如下: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...
- Web Services and C# Enums
Web Service Transparency .NET support for web services is excellent in creating illusion of transpar ...
- <亲测>用navicat连接mysql 8.0 报错2059
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded 2018年05月07日 15:56 ...
- 测试教程网.unittest教程.7. 各种断言方法
From: http://www.testclass.net/pyunit/assert/ 背景 unittest支持各种断言方法. 断言列表 官方文档 方法 检查点 assertEqual(a, b ...
- boost::function用法详解
要开始使用 Boost.Function, 就要包含头文件 "boost/function.hpp", 或者某个带数字的版本,从 "boost/function/func ...