首页 > 解决方案 > 启用“Do-Not-Track”- Selenium 中的功能(Python)

问题描述

Selenium (使用Python)有没有办法启用“Do-Not-Track”功能?

我的意思是浏览器(在我的例子中:Firefox geckodriver)检索用户地理位置的限制。

我知道这是可能的,这里是 GitHub 上的一个类似问题,但是 1.它是用 JavaScript 编写的,2.它只是不起作用。

有谁知道解决方案?

到目前为止,这是我的代码:

import selenium.webdriver

profile = FirefoxProfile()
profile.set_preference("javascript.enabled", False)
options = webdriver.firefox.options.Options()
options.headless = True
profile.update_preferences()
browser = webdriver.Firefox(firefox_profile=profile, options=options)

browser.get("https://thesafety.us/check-ip")


谢谢

标签: pythonseleniumfirefoxdo-not-track

解决方案


我找到了解决方案。我只需将以下内容添加到我的代码中:

fp = webdriver.FirefoxProfile()
fp.DEFAULT_PREFERENCES['frozen']["privacy.trackingprotection.enabled"] = True

顺便说一下,例如,您也可以替换dom.disable_open_during_loadmedia.peerconnection.ice.default_address_only禁用 WebRTC。


推荐阅读