这个问题已经在这里有了答案: > Python/Selenium incognito/private mode 7个
我有以下脚本:
#!/usr/bin/python3
from selenium import webdriver
import time
def getProfile():
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.privatebrowsing.autostart", True)
return profile
def main():
browser = webdriver.Firefox(firefox_profile=getProfile())
#browser shall call the URL
browser.get("http://www.google.com")
time.sleep(5)
browser.quit()
if __name__ == "__main__":
main()
如何管理Firefox以私有模式启动?
解决方法:
参考@Laas在How might I simulate a private browsing experience in Watir? (Selenium)处的观点:
Selenium is equivalent to turning on Private browsing.
以及“Private Browsing”的定义:
Private browsing allows you to browse the Internet without saving any
@R_479_4045@ion about which sites and pages you’ve visited.
而且,由于每次通过Selenium Webdriver启动Firefox都会创建一个全新的匿名配置文件,因此您实际上是在私下浏览.
如果仍然要在Firefox中强制使用私有模式,请将browser.privatebrowsing.autostart配置选项设置为true:
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(firefox_profile=firefox_profile)
另请参阅:
> Python/Selenium incognito/private mode
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。