zoukankan      html  css  js  c++  java
  • Selenium+Headless Firefox配置

    selenium不再支持phantomjs

    在不打开浏览器的前提下,使用所有 firefox支持的特性运行你的程序。

    开始准备用Chrome来试的,没成功。firefox弄成功了

    geckoderiver下载

    geckoderiver可以从https://github.com/mozilla/geckodriver/releases处下载

    from selenium import webdriver
    options = webdriver.FirefoxOptions()
    options.set_headless()
    # options.add_argument(‘-headless‘)
    options.add_argument(‘--disable-gpu‘)
    driver=webdriver.Firefox(firefox_options=options)
    driver.get('http://httpbin.org/user-agent')
    print(driver.page_source)
    driver.close()
    会报错python3 UnicodeEncodeError: 'gbk' codec can't encode character 'xXX' in position XX


    print()方法在Win7的默认编码是gbk,它在打印时,并不是所有的字符都支持的。
    而且这个问题一般也就是在cmd中才会有。

    在cmd中是改变标准输出编码:

    import io  
    import sys 
    #改变标准输出的默认编码 
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
    print(driver.page_source)成功


  • 相关阅读:
    容器常用命令
    镜像常用命令
    Docker安装
    Jenkins部署
    IIS配置伪静态 集成模式 样式丢失
    centos7 apache 配置ssl
    centOS7 关闭swap
    Presto集群部署和配置
    HDFS中将普通用户增加到超级用户组supergroup
    superset在 centos 7安装运行
  • 原文地址:https://www.cnblogs.com/peterleee/p/9373765.html
Copyright © 2011-2022 走看看