Python - 在私有模式下使用Selenium启动firefox

时间:2014-12-11 14:23:58

标签: python firefox selenium selenium-webdriver

我有以下脚本:

#!/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以私有模式启动?

1 个答案:

答案 0 :(得分:14)

参考@ Laas在How might I simulate a private browsing experience in Watir? (Selenium)的观点:

  

Selenium相当于打开私人浏览。

"Private Browsing"的定义:

  

私密浏览允许您浏览互联网而不保存任何内容   有关您访问过哪些网站和网页的信息。

因为每次你通过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)

另见,见:

相关问题