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 计算校验和
校验和是经常使用的,这里简单的列了一个针对按字节计算累加和的代码片段.其实,这种累加和的计算,将字节翻译为无符号整数和带符号整数,结果是一样的. 使用python计算校验和时记住做截断就可以了. 这里 ...
- ubuntu 阿里云 常出问题 运维工作日志
一.2015-8.26(数据库 error—28) tmp文件临时数据写入不了----解决办法 1.查看临时文件 ls -l 找到了 2.由此可以查看得出来tmp文件有的权限是有的 3.查看tmp 存 ...
- 获取一个div下的li或者img元素
上层div的xpath=//*[@id="launchpadOptionsList"] 其下的所有li的最后一个是//*[@id="launchpadOptionsLis ...
- 常用的几个vagrant命令
$ vagrant init # 初始化 $ vagrant up # 启动虚拟机$ vagrant halt # 关闭虚拟机$ vagrant reload ...
- C#批量更新mongodb符合条件的数据
默认情况下只会更新匹配的第一条 jingjiaanalyurl.Update(Query.EQ("auid", jingjiaitem.id), Update.Set(" ...
- Memcached在.NET应用程序中的使用
在应用程序运行的过程中总会有一些经常需要访问并且变化不频繁的数据,如果每次获取这些数据都需要从数据库或者外部文件系统中去读取,性能肯定会受 到影响,所以通常的做法就是将这部分数据缓存起来,只要数据没有 ...
- PAT 乙级 1070 结绳(25) C++版
1070. 结绳(25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一段一段的绳子,你需要把它们串成一条 ...
- 其他类想使用unittest的断言方法,就import unittest的框架,继承他,使用他里面的方法
在断言层 也可以同样用这个方法
- 产品使用的前后台框架API-dubbo-redis-elasticsearch-jquery
前台框架API •jQuery:https://jquery.com/ •jQuery MiniUI:http://www.miniui.com/ •Bootstrap:http://www.boot ...
- centos6.9安装oracle11g
感谢强哥的文档 源文档链接 https://www.qstack.com.cn/archives/68.html #------------------------------------------ ...