我用python,selenium和firefox运行这段代码,但仍然得到firefox的'head'版本:
binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)
binary.add_command_line_options('-headless')
self.driver = webdriver.Firefox(firefox_binary=binary)
Run Code Online (Sandbox Code Playgroud)
我也尝试了二进制的一些变体:
binary = FirefoxBinary('C:\\Program Files\\Nightly\\firefox.exe', log_file=sys.stdout)
binary.add_command_line_options("--headless")
Run Code Online (Sandbox Code Playgroud) python selenium python-3.x selenium-webdriver firefox-headless
我想知道为什么会收到以下错误消息以及如何修复它:
回溯(最近一次调用):<\module> 中的文件“teste.py”,第 30 行
主要的()
文件“teste.py”,第 24 行,在主目录中
驱动程序 = connectFirefox(defineOptions())
文件“teste.py”,第 18 行,在 connectFirefox 中
驱动程序 = webdriver.Firefox(firefox_options=options)
文件“/usr/lib/python3.6/site-packages/selenium/webdriver/firefox /webdriver.py”,第 125 行,在init 中
如果 options.binary 不是 None:
AttributeError: 'Options' 对象没有属性 'binary'
我的代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.chrome.options import Options
def defineOptions():
options = Options()
options.add_argument("--headless")
return options
def connectChrome(options):
chromeDriverPath = "/usr/bin/chromedriver"
driver = webdriver.Chrome(chromeDriverPath, chrome_options=options)
print("Chrome Headless Browser Invoked")
return driver
def connectFirefox(options):
driver = webdriver.Firefox(firefox_options=options)
print("Firefox Headless Browser Invoked")
return …Run Code Online (Sandbox Code Playgroud) python headless-browser google-chrome-headless firefox-headless
正如标题所说,我无法以非 root 用户身份在 Docker 容器内以无头模式运行 Firefox。考虑以下 Dockerfile,构建于docker build -t firefox .
FROM python:3.8-buster
RUN apt-get update -qq \
&& apt-get install -qy \
libappindicator1 \
libasound2 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm-dev \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libpci-dev \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \ …Run Code Online (Sandbox Code Playgroud) 黎明时我的代码工作得很好,但是今天当我醒来时它不再工作了,我没有更改任何代码行,我还检查了 Firefox 是否更新了,不,它没有,我没有想法可能是什么,我一直在阅读 urllib 文档,但找不到任何信息
\nfrom asyncio.windows_events import NULL\nfrom ctypes.wintypes import PINT\nfrom logging import root\nfrom socket import timeout\nfrom string import whitespace\nfrom tkinter import N\nfrom turtle import color\nfrom urllib.request import Request\nfrom hyperlink import URL\nfrom selenium import webdriver\nfrom selenium.webdriver.firefox.service import Service\nfrom selenium.webdriver.firefox.options import Options\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support.expected_conditions import presence_of_element_located\n#from webdriver_manager.firefox import GeckoDriverManager\nimport time\nfrom datetime import datetime\nimport telebot\n\n#driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))\n\ncolors = NULL\napi = "******"\nurl = "https://blaze.com/pt/games/double"\nbot = telebot.TeleBot(api)\n\nchat_id = "*****"\n\nfirefox_driver_path = "/Users/Ant\xc3\xb4nio/Desktop/roletarobo/geckodriver.exe"\nfirefox_options = Options()\nfirefox_options.add_argument("--headless")\nwebdriver = …Run Code Online (Sandbox Code Playgroud) 将 selenium webdriver 设置为无头模式后是否可以将其设置回正常模式?
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get(http://stackoverflow.com)
# set driver back to normal mode
Run Code Online (Sandbox Code Playgroud) python selenium-chromedriver selenium-firefoxdriver google-chrome-headless firefox-headless
当我抓取包含使用无头选项的产品的页面时,我得到不同的结果。
对于同一问题,一次我得到的结果未排序,另一次得到正确排序的结果。
硒火狐浏览器:
firefox_options = Options()
firefox_options.headless = True
browser = webdriver.Firefox(options=firefox_options, executable_path=firefox_driver)
Run Code Online (Sandbox Code Playgroud)
根据这篇文章:
“当使用无头选项时,Firefox 不会发送不同的标头”。
如何使用无头选项从抓取中获得恒定的结果?
更新:
事实证明,广告弹出窗口隐藏了价格排序菜单。通过设置DebanjanB发布的恒定窗口大小,问题得到了解决。
感谢您的任何建议
python selenium headless-browser geckodriver firefox-headless
我无法使用 Firefox (v60.9.0)无头模式生成本地 HTML 文件的屏幕截图
这是我正在使用的命令:
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P AJ --screenshot test.png "file:///C:/html_export.html"
Run Code Online (Sandbox Code Playgroud)
我尝试过使用和不使用配置文件以及文件后使用不同数量的斜杠。命令行中没有错误 - 它只是不生成输出。
当我用外部网站替换 file:// 时,此命令工作正常,例如:
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P AJ --screenshot test.png google.com
Run Code Online (Sandbox Code Playgroud)
这可能与这里提到的重定向错误有关吗?
任何帮助表示赞赏!也许有一种方法可以打开 --headless 模式的输出详细程度?
我正在尝试使用 python 和 selenium 在 Firefox 无头模式下自动化某些情况。我想,我做了我需要的所有设置,但仍然没有初始化 webdrvier。
我的问题是在执行我的代码后大约 30-60 秒收到异常并且异常消息不清楚实际上消息部分是空的。正如您在无头模式下运行的 geckodriver.log firefox 上看到的那样。
我使用 Firefox 56.0.1、python 3.6、selenium 3.141.0。这是我的代码和日志;
代码:
import os
import time
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
options = Options()
options.set_headless(True)
dir = "C:\\Python36\\Lib\\site-packages\\selenium\\webdriver\\firefox"
ff_driver_path = dir + "\\geckodriver.exe"
firefox_capabilities = DesiredCapabilities().FIREFOX
firefox_capabilities['marionette'] = True
profile = webdriver.FirefoxProfile()
binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla …Run Code Online (Sandbox Code Playgroud) python selenium selenium-firefoxdriver geckodriver firefox-headless
python ×6
selenium ×4
geckodriver ×3
firefox ×2
docker ×1
playwright ×1
python-3.x ×1
scrapy ×1