zoukankan      html  css  js  c++  java
  • 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 入门地址

  • 相关阅读:
    cafebabe go入门练习003:常量与iota
    go入门练习002:查找重复的行
    go入门练习001:打印命令行输入
    go入门-002-程序结构
    [ES6深度解析]10:Generators 续集
    [JavaScript初级面试]17. 运行环境
    [JavaScript初级面试]16. 运行环境
    [JavaScript初级面试]10. WEB API
    [JavaScript初级面试]8. WEB API
    [JavaScript初级面试]7. WEB API
  • 原文地址:https://www.cnblogs.com/zxpo/p/8288663.html
Copyright © 2011-2022 走看看