如何使用Selenium在PhantomJS中设置浏览器首选项

2024-04-29 04:24:21 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有什么方法可以像phantomJS中的"network.negotiate-auth.trusted-uris"那样使用浏览器首选项。在

下面是selenium with firefox的语法:

p_profile = webdriver.FirefoxProfile()
p_profile.set_preference("network.negotiate-auth.trusted-uris", "https://xx.com")
driver = webdriver.Firefox(p_profile)
driver.get("https://xx.com")

PhantomJS中是否有类似的功能。在


Tags: 方法httpscomauthdriver浏览器networkphantomjs
1条回答
网友
1楼 · 发布于 2024-04-29 04:24:21

您可以在创建PhantomJS对象时传递desired_capabilities关键字参数。在

例如,要更改用户代理标头:

from selenium import webdriver


cap = webdriver.DesiredCapabilities.PHANTOMJS.copy()                            
cap['phantomjs.page.settings.userAgent'] = 'asdf'
driver = webdriver.PhantomJS(desired_capabilities=cap)
driver.get('http://httpbin.org/headers')
print(driver.page_source)
driver.quit()

检查^{} - PhantomJS以获取其他可用设置。在

相关问题 更多 >