selenium +chrome headless Adhoc模式渲染网页
mannual和adhoc模式比较
Manual vs. Adhoc
In the script above, we start the ChromeDriver server process when we create the WebDriver object and it is terminated when we call quit(). For a one-off script, that isn’t a problem, but this can waste a nontrivial amount of time for a large test suite that creates a ChromeDriver instance for each test. Luckily, we can manually start and stop the server ourselves, and it only requires a few changes to the script above.
说的在使用selenium+chromeheadless做自动化测试时候,如果测试用例数量大,给每个测试用例启动一个浏览器要话费更多的时间。 #coding=utf8
import os,traceback
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
service = webdriver.chrome.service.Service('/home/xxxx/Downloads/phantomjs-2.1.1-linux-x86_64/bin/chromedriver')
service.start()
class ChromeHeadless(object):
def __init__(self):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-images')
chrome_options.add_argument('--disable-plugins')
chrome_options.binary_location = '/opt/google/chrome/chrome'
#prefs = {"profile.managed_default_content_settings.images": 2} # 关图片
#chrome_options.add_experimental_option("prefs", prefs)
self.chrome_options=chrome_options
self.driver = webdriver.Remote(service.service_url,desired_capabilities=self.chrome_options.to_capabilities())
self.driver.set_page_load_timeout(120)
def fun(self,url):
try:
proxy_http_list = list(r.smembers('kuaidaili:http')) + list(r.smembers('zhima'))
pr=random.choice(proxy_http_list)
self.chrome_options.add_argument('--proxy-server=%s'%pr) #设置代理
self.driver.start_session(self.chrome_options.to_capabilities())
#print self.driver.session_id
self.driver.get(url)
except Exception,e:
print '\033[7;32;0m%s\033[0m' %traceback.format_exc()
selenium +chrome headless Adhoc模式渲染网页的更多相关文章
- selenium +chrome headless Manual 模式渲染网页
可以看看这个里面的介绍,写得很好.https://duo.com/blog/driving-headless-chrome-with-python from selenium import webdr ...
- ubuntu服务器端使用无界面selenium+ chrome + headless
本来想直接用Ubuntu系统里面的firefox来实现selenium自动操作签到的,但是总是出各种问题.没办法,改为Chrome.参考:Ubuntu 线上无界面服务器 使用selenium chro ...
- 笔记-selenium+chrome headless
笔记-selenium+chrome headless 1. selenium+chrome headless phantomjs与selenium分手了,建议使用其它无头浏览器. chro ...
- chrome浏览器爬虫WebDriverException解决采用python + selenium + chrome + headless模式
WebDriverException: Message: unknown error: Chrome failed to start: crashed 第一种:如果出现下面情况: chrome浏览器有 ...
- selenium chrome headless无界面引擎
注意:PhantomJS已被舍弃 chrome headless 在打开浏览器之前添加参数 import time import sys from selenium import webdriver ...
- Selenium + Chrome headless 报ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context 可忽略并配置不输出日志
Selenium不再推荐使用PhantomJS,会报如下警告 UserWarning: Selenium support for PhantomJS has been deprecated, plea ...
- ubuntu中如何安装selenium+chrome(headless)无界面浏览器?
selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...
- Ubuntu 无界面使用selenium chrome + headless
1. 安装 selenium : sudo pip install selenium 2. 安装 chromdriver: 进入 淘宝镜像源 下载 chromdriver, 可以查看 notes.tx ...
- 关于强制IE不使用兼容模式渲染网页
现在IE11是唯一受微软支持的IE浏览器. IE11有兼容模式,开启后有网页会出错. 在html header标签下加上 <meta http-equiv="X-UA-Compatib ...
随机推荐
- ctags简易用法
vim + ctags a 首先我们必需给要阅读的原始码建一个或多个tags文件, 在shell下利用ctags命令给单个文件建立tags如下: $ ctags filename.c 要给同一个目录下 ...
- Spring WebSocket教程(二)
实现目标 这一篇文章,就要直接实现聊天的功能,并且,在聊天功能的基础上,再实现缓存一定聊天记录的功能. 第一步:聊天实现原理 首先,需要明确我们的需求.通常,网页上的聊天,都是聊天室的形式,所以,这个 ...
- android 技术点记录
Android Service完全解析,关于服务你所需知道的一切(上) http://blog.csdn.net/guolin_blog/article/details/11952435 androi ...
- Volatile和Transient
Volatile: Volatile修饰的成员变量在每次被线程访问时,都强迫从主内存中重读该成员变量的值.而且,当成员变量发生变化时,强迫线程将变化值回写到主内存.这样在任何时刻,两个不同的线程总是看 ...
- Extjs4.2 Grid搜索Ext.ux.grid.feature.Searching的使用
背景 Extjs4.2 默认提供的Search搜索,功能还是非常强大的,只是对于国内的用户来说,还是不习惯在每列里面单击好几下再筛选,于是相当当初2.2里面的搜索,更加的实用点,于是在4.2里面实现. ...
- JQuery操作cookies
jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and valu ...
- Linux共享库 配置文件读取
#ifndef __INIPARSERHELPER_H_ #define __INIPARSERHELPER_H_ #define IN #define OUT #define INOUT typed ...
- 关于go语言的环境配置 SDK+path+工作目录
第一步: 安装Golang的SDK http://golang.org,下载最新的安装包,之后双击安装即可. 安装完成之后,打开终端,输入go.或者go version(查看安装版本)出现如下信息即表 ...
- android读取大图片并缓存
最近开发电视版的云存储应用,要求”我的相册“模块有全屏预览图片的功能,全屏分辨率是1920*1080超清.UI组件方面采用Gallery+ImageSwitcher组合,这里略过,详情参见google ...
- tomcat部署时war和war exploded区别
war模式—-将WEB工程以包的形式上传到服务器 war exploded模式—-将WEB工程以当前文件夹的位置关系上传到服务器