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错误.那么当 ...
随机推荐
- Delphi中使用ADO连接Excel
第一部分: . 设置ADOConnection的ConnectionString属性的OLE DB的提供者要选择Microsoft Jet 4.0 OLE DB Provider(这本来是用于连接Ac ...
- python基本知识点
1.基本数据类型 1.1int 字符串转换为数字,比如 a = “123” print(type(a) , a) b = int(a) print(type(b),b) num = “b” v = i ...
- win7下python2.6如何安装setuptools和pip
1. 下载 setuptools-0.6c9.tar.gz 下载地址:http://pypi.python.org/packages/source/s/setuptools/setuptools-0. ...
- 51nod 1132 覆盖数字的数量 V2
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1132 题意是给定a,b,l,r求[l,r]内有几个整数可以表示成ax+b ...
- 【ZZ】详解哈希表的查找
详解哈希表的查找 https://mp.weixin.qq.com/s/j2j9gS62L-mmOH4p89OTKQ 详解哈希表的查找 2018-03-01 算法与数据结构 来自:静默虚空 http: ...
- logging模块知识点及应用小结
Logging模块知识点: 一.分为5个级别:debug(),info(),warning(),error(),critical().级别由低到高 1.1最简单的用法: 1.2 如果想把日志写到文件 ...
- 智行火车票免费加速到VIP最高速抢票(不用朋友积攒或者购买加速包)
更新: 2018.11.07, 昨天我买火车票,已经不行了,这个bug已经没有了,被修复了, 望大家知悉!!! 智行火车票免费加速到VIP最高速抢票(不用朋友积攒或者购买加速包) 1)下过单后选择抢到 ...
- [UE4]运行时进入观察模式
- tensorFlow 三种启动图的用法
tf.Session(),tf.InteractivesSession(),tf.train.Supervisor().managed_session() 用法的区别: tf.Session() 构 ...
- mysql数据库数据备份与恢复
备份数据: C:\Users\Administrator>mysqldump -uroot --password -v test01 test02 >e:\temp\\a3.sql Ent ...