【问题标题】:Mismatch in UserAgent initiating Firefox manually and using GeckoDriver手动启动 Firefox 并使用 GeckoDriver 的 UserAgent 不匹配
【发布时间】:2022-02-10 03:55:16
【问题描述】:

为什么两种情况下的用户代理不一样?

https://www.whatsmyua.info/ 在我使用普通 Firefox 浏览时报告以下内容:

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0

但是,使用 geckodriver 报告浏览:

Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0

以下是我开始使用 geckodriver 浏览的方式:

options=Options()
profile_path = '/home/myuser/.mozilla/firefox/x9zoqd7t.default-release/'
options.set_preference('profile', profile_path)
service = Service('/usr/local/bin/geckodriver')
driver = Firefox(service=service, options=options)
driver.get("http://www.whatsmyua.info/")

【问题讨论】:

    标签: selenium selenium-webdriver firefox user-agent geckodriver


    【解决方案1】:

    手动访问 Firefox v97.0 并访问 Selenium 驱动 GeckoDriver v0.30.0 发起浏览上下文,无论哪种方式我看到相同的User Agent 如下:

    Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0
    

    不匹配的最可能原因是,您安装了 2 个 Firefox 浏览器实例。

    您手动访问的实例没有更新,因为它是 96.0 的旧版本,因为实例安装在位置 /home/myuser/.mozilla/firefox/ 91.0 以来没有更新。因此,您观察到 useragent 的差异

    【讨论】:

    • 你说得对,我发现安装了另一个版本!顺便说一句,geckodriver 在用户代理中不会将自己呈现为无头或机器人。这正常吗?
    • @Rimfire 我还没有研究 geckodriver 是否在用户代理中不显示为 headless 或 bot 的细节。如果您有具体问题,请随时提出,我想深入挖掘以帮助您。
    猜你喜欢
    • 2017-06-23
    • 2017-09-23
    • 2018-01-13
    • 2017-09-03
    • 2020-06-16
    • 2019-01-11
    • 2019-10-31
    • 1970-01-01
    • 2019-03-13
    相关资源
    最近更新 更多