Python - 在私有模式下启动Selenium的Firefox [英] Python - Start firefox with Selenium in private mode

查看:690
本文介绍了Python - 在私有模式下启动Selenium的Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #!/ usr / bin / python3 $ b $ se from selenium import webdriver 
导入时间
$ b $ def getProfile():
profile = webdriver.FirefoxProfile()
profile.set_preference(browser.privatebrowsing.autostart,True)
返回配置文件

def main():
browser = webdriver.Firefox(firefox_profile = getProfile())

#browser将调用URL
browser.get(http://www.google.com)
time.sleep(5)
browser.quit()

if __name__ ==__main__ :
main()

如何管理Firefox以私人模式启动? p>

解决方案

引用@ Laas的观点
$ b


Selenium相当于打开Private Browsing。




并定义:私密浏览


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


自从您每次使用selenium webdriver启动Firefox时,一个全新的匿名配置文件你实际上正在私下浏览




如果你还想强制Firefox中的私人模式,将 browser.privatebrowsing.autostart 配置选项设置为 true

 来自selenium import webdriver 

firefox_profile = webdriver.FirefoxProfile()
firefox _profile.set_preference(browser.privatebrowsing.autostart,True)

driver = webdriver.Firefox(firefox_profile = firefox_profile)

另请参阅:


I have the following script:

#!/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()

How can I manage Firefox to start in private mode?

解决方案

Referring to the @Laas's point at How might I simulate a private browsing experience in Watir? (Selenium):

Selenium is equivalent to turning on Private Browsing.

And the definition of "Private Browsing":

Private Browsing allows you to browse the Internet without saving any information about which sites and pages you’ve visited.

And since every time you start firefox through selenium webdriver it creates a brand new anonymous profile, you are actually browsing privately.


If you still want to force the private mode in Firefox, set the browser.privatebrowsing.autostart configuration option to true:

from selenium import webdriver

firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)

driver = webdriver.Firefox(firefox_profile=firefox_profile)

Also, see:

这篇关于Python - 在私有模式下启动Selenium的Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆