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 ...
随机推荐
- Quartz Trigger Priority 触发器优先级
Quartz Trigger Priority 触发器优先级 当多个触发器在一个相同的时间内触发,并且调度引擎中的资源有限的情况下,那么具有较高优先级的触发器先触发. 需要将配置文件中的org.qua ...
- hbase源码系列(一)Balancer 负载均衡
看源码很久了,终于开始动手写博客了,为什么是先写负载均衡呢,因为一个室友入职新公司了,然后他们遇到这方面的问题,某些机器的硬盘使用明显比别的机器要多,每次用hadoop做完负载均衡,很快又变回来了. ...
- 详解Github的.gitignore忽略文件+.gitignore不生效解决方案+生产配置大奉送
详解Github的.gitignore忽略文件+.gitignore不生效解决方案+生产配置大奉送 Git中有一个非常重要的一个文件-----.gitignore 今天给大家免费送一个.gitigno ...
- jQuery运行方式818
我们平时打开JQ源码就会看到这么一段代码 (function (window, undefined) { //JQ代码 })(window) 有一点经验的朋友会知道这是js自执行函数 它的好处主要作用 ...
- 【转】web前端到底怎么学?干货资料!
一般据我经验,在喜欢并且决定和她恋爱之前,我都会做一下充分准备和调查,有必要了解和研究清楚 ‘她’ 的几个特性和习惯 web前端的基本工作职责 和基础技能(要清楚) web前端的分类和门派(简要概述, ...
- C/C++文件输入输出操作——FILE*、fstream、windowsAPI
基于C的文件操作在ANSI C中,对文件的操作分为两种方式,即流式文件操作和I/O文件操作,下面就分别介绍之. 一.流式文件操作这种方式的文件操作有一个重要的结构FILE,FILE在头文件stdio. ...
- 深入浅出SIP协议
传统电话是电磁波的通信,当电话技术发展到IP技术时代,SIP协议成为了电话通信标准协议,不仅可以通电话.还可以收发信息.视频.开会.放PPT.事实上,今天的通信业已全面采用SIP协议作为通信标准,无论 ...
- Textrank权值提取文本标签提取:
Textrank权值提取文本标签提取: 我已经爬取到了指定博主的新浪微博,然后我想从微博中提取出可以代表该博主兴趣特征的100个关键词,然后由这100个关键词提取出10个标签,代表博主的兴趣.我们此处 ...
- 关于Unity中的光照(七)
全局光照 GI 这里所说的反射就是,一个红色的物体,当太阳照射它的时候,它周围的物体也会变得有点红. 1:Realtime每帧都会计算光照,实时光照是不会反射的,所以它的光影显得单调;2:Baked ...
- Opencv-Python:图像尺寸、图像的读取、显示、保存与复制
Opencv-Python:图像尺寸.图像的读取.显示.保存与复制 原创 2017年11月23日 21:30:49 4440 在使用opencv的方法时,首先必须导入opencv包.新的opencv导 ...