selenium+headless chrome安装使用
pip install selenium
因为phantomJS将停止维护,所以建议使用headless chrome
ChromeDriver is a separate executable that WebDriver uses to control Chrome.
1、确保谷歌浏览器安装在可以找到的位置(默认位置或自己指定的位置)。
如果不是默认位置,则需要用下面的代码来指定谷歌浏览器的安装位置:
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");
2、下载你系统上所需要的ChromeDriver文件,windows所需下载地址为:
https://chromedriver.storage.googleapis.com/index.html?path=2.35/
3、帮助WebDriver找到你下载的ChromeDriver文件:
将ChromeDriver文件存放在PATH目录下或
或
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver')
4、(可选)启动和退出ChromeDriver server需要一些时间,所以提供了两种方法来
解决这个问题:
1、使用ChromeDriverService
2、作为一个服务器单独启动ChromeDriver server,然后用Remote WebDriver连接它。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.baidu.com")
print(driver.title)
driver.quit()
参考链接:
https://sites.google.com/a/chromium.org/chromedriver/home 介绍地址
https://sites.google.com/a/chromium.org/chromedriver/getting-started 入门地址
最新文章
- os.path 大全
- jquery---基本标签
- spring4 文件下载功能
- JSPatch 遇上swift
- Android类库常用类库一览
- (转)CSS+DIV float 定位
- Codeforces Round #327 (Div. 1) D. Top Secret Task
- adb shell dumpsys 命令 查看内存
- 目前比较流行的Python科学计算发行版
- mybatis源码之MapperMethod
- Android--app性能问题的总结(一)
- 高德地图 Service 创建服务 USERKEY_PLAT_NOMATCH
- Ubuntu 18.04.1安装Nginx
- BootStrapTable 错误
- vue-cli(vue脚手架)超详细教程
- loadrunner 更新中......
- 【转】Android开源项目(非组件)
- Odoo前端页面模版渲染引擎——Jinja2用法教程
- 【转】netty源码分析之LengthFieldBasedFrameDecoder
- asp.net线程批量导入数据时通过ajax获取执行状态