打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
selenium设置火狐浏览器为headless(无头模式)

selenium已经停止了对PhantomJS的支持,只能调用Firefox或者Chrome浏览的无头模式(即没有浏览器界面)。
使用步骤:

  1. 安装Firefox浏览器
    firefox历年版本安装包的官方镜像地址:
    https://download-installer.cdn.mozilla.net/pub/firefox/releases/
  2. 安装geckodriver驱动
    (1)下载geckodriver
    火狐所有的geckodriver.exe驱动大全下载链接如下:https://github.com/mozilla/geckodriver/releases
    (2)将geckodriver所在路径加入环境变量path当中
    网上提到的有几种方法,一是将geckodriver.exe复制到Python的scripts目录,二是将geckodriver.exe复制到Firefox安装目录,然后再把Firefox安装目录加入到环境变量path中
  3. 编写代码
from selenium import webdriver
options = webdriver.FirefoxOptions()
#options.set_headless(True)
options.add_argument("--headless") #设置火狐为headless无界面模式
options.add_argument("--disable-gpu")
driver = webdriver.Firefox(options=options)
driver.get("https://www.qq.com")
driver.get_screenshot_as_file("test.png")
driver.quit()
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
在Python Selenium中为Chrome和Firefox浏览器开启headless模式 | 李辉的个人网站
Selenium简单实践,登录QQ邮箱和QQ空间
Selenium & Firefox Driver安装_firefoxdriver
selenium+python自动化85-Chrome静默模式(headless)
Python使用浏览器模拟访问页面之使用ip代理
Python+Selenium安装及环境配置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服