相关疑难解决方法(0)

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

我有以下脚本:

#!/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()
Run Code Online (Sandbox Code Playgroud)

如何管理Firefox以私有模式启动?

python firefox selenium selenium-webdriver

9
推荐指数
1
解决办法
2万
查看次数

Python Selenium Firefox 使用 cookie 进行私密浏览

我需要使用 Firefox 和 Python 通过 Webdriver 添加 cookie。它在正常模式下工作,但在private模式下无效。

from selenium import webdriver
capabities = webdriver.DesiredCapabilities.FIREFOX
capabities.update({"javascriptEnabled":True})
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(desired_capabilities=capabities, firefox_profile=firefoxProfile)
driver.get("http://httpbin.org/cookies")
driver.add_cookie({"name":"drag", "value": "lol", "domain": "httpbin.org"})
driver.get("http://httpbin.org/cookies")
Run Code Online (Sandbox Code Playgroud)

无论我刷新驱动程序多少次,cookie 都不会加载。document.cookie控制台日志中没有任何内容。它在 Chrome(未在隐身模式下测试)和 Firefox(非私有)中运行良好。

我知道在 selenium 私有模式中是多余的,我已经阅读了这个 SO 问题以及这个.

但我无法更改大部分代码。即使在 Firefox 的私有模式下,我也需要这个功能来设置 cookie。

火狐 66.0.1

Geckodriver 0.23.0 ( 2018-10-04)

Python 硒 3.14.1

编辑 1

我已经用 chrome(incognito) 测试过,它似乎工作

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
capabities = webdriver.DesiredCapabilities.CHROME
capabities.update({"javascriptEnabled":True})
driver …
Run Code Online (Sandbox Code Playgroud)

python cookies firefox selenium selenium-webdriver

6
推荐指数
0
解决办法
483
查看次数

Selenium,执行时如何不打开隐身模式

当我执行时

driver = webdriver.Chrome('/Users/sunghunkwak/PythonTesting/chromedriver')
driver.get("https://gmail.com")
Run Code Online (Sandbox Code Playgroud)

它总是打开隐身模式(秘密、私人模式)。但是,我想使用原来的 Chrome。我该怎么做?

谢谢。

python selenium google-chrome

5
推荐指数
1
解决办法
1632
查看次数

chromedriver clear cache - java

如何在java中清除chromedriver的新实例的缓存?我正在尝试这个,但我不太确定还能做什么?是否有可能创建一个javascript hack来清除JS中的缓存,我可以从我的驱动程序调用?

private static WebDriver makeDriver() {
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    ChromeDriver driver = new ChromeDriver();
    driver.manage().deleteAllCookies();
    return driver;
}
Run Code Online (Sandbox Code Playgroud)

javascript java selenium selenium-chromedriver

4
推荐指数
1
解决办法
2万
查看次数