python - 启用“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")
谢谢
解决方案
我找到了解决方案。我只需将以下内容添加到我的代码中:
fp = webdriver.FirefoxProfile()
fp.DEFAULT_PREFERENCES['frozen']["privacy.trackingprotection.enabled"] = True
顺便说一下,例如,您也可以替换dom.disable_open_during_load
为media.peerconnection.ice.default_address_only
禁用 WebRTC。
推荐阅读
- dart - Flutter:主题未应用于文本小部件
- javascript - 如何在 React 中使用 setInterval?
- c# - 如何在授权类文件中随机生成一个数字或字符
- node.js - POST 请求不包含带有 Satellizer、Express 和 google auth 的“正文”字段
- javascript - 如何解决 Uncaught TypeError: Cannot set property 'value' of undefined error in javascript?
- ms-access - 在表单中使用组合框时 ms 访问不需要的“输入参数值”
- android - 为什么recyclerView的viewholder在Android中隐藏视图时为空?
- php - 使用 Angular 5 将 POST 数据发送到 php
- jquery - DataTable ajax 重新加载不起作用
- powershell - foreach 循环:如何在循环内更新集合变量?