zoukankan      html  css  js  c++  java
  • centos7上PhantomJS 过期之后改用Chrome时填的坑

    突然有个自动化需求所以准备使用模拟点击的方法,

    在使用之前的PhantomJS时,报错

    UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome ……

    这时候的方法就是换到chrome了,如果你没装过,那么可以按照这里的方法去安装,如果已经安装了,也建议按照这里的方法去排查可能出现的问题,

    For Linux

    1. Check you have installed latest version of chrome brwoser-> chromium-browser -version
    2. If not, install latest version of chrome sudo apt-get install chromium-browser
    3. get appropriate version of chrome driver from here
    4. Unzip the chromedriver.zip
    5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
    6. Goto /usr/bin directory cd /usr/bin
    7. Now, you would need to run something like sudo chmod a+x chromedriver to mark it executable.
    8. finally you can execute the code.

      from selenium import webdriver
      
      driver = webdriver.Chrome()
      driver.get("http://www.google.com")
      print driver.page_source.encode('utf-8')
      driver.quit()
      display.stop()

    这样只会就应该可以用了,

    如果还报错,selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions.

    那极有可能是你没把执行路径添加到path,或者添加的路径不完整,全路径应该是包含chromedriver这个文件名的,不能只写到它所在的文件夹,

    eg,

    chrome_path = '/usr/bin/chromedriver'
    这样就可以了,下面是测试代码,正常执行的,
    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')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-extensions')
    
    chrome_path = '/usr/bin/chromedriver'
    driver = webdriver.Chrome(executable_path=chrome_path, chrome_options=chrome_options)
    
    driver.get("https://cnblogs.com/")
  • 相关阅读:
    常见错误及解决方案
    使用7zip压解各种文件的经常使用命令
    《鸟哥的Linux私房菜-基础学习篇(第三版)》(六)
    一起talk C栗子吧(第一百二十四回:C语言实例--内置宏)
    逻辑学和计算理论相关概念
    书评第003篇:《0day安全:软件漏洞分析技术(第2版)》
    解释器模式
    面试复习重点——数据结构、操作系统、计算机网络、数据库。
    我们凭什么年薪达到30万以上?
    测试工作中的问题清单
  • 原文地址:https://www.cnblogs.com/1394htw/p/10309390.html
Copyright © 2011-2022 走看看