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/")
  • 相关阅读:
    巴基斯坦:软件服务外包行业的后来者 (zz)
    对象集合查询
    我的db类库 新版
    得到web.config里配置项的数据库连接字符串
    jdk环境变量配置
    FastReport v3.2.5在BDS2006中的安装方法
    CONFIG.SYS文件的命令与配置
    DOS下内存的配置
    动态注册ODBC数据源的通用方法
    XP下安装装SQL2000企业版本
  • 原文地址:https://www.cnblogs.com/1394htw/p/10309390.html
Copyright © 2011-2022 走看看