如何使用Python将选项传递给Selenium Chrome驱动程序?
我们可以使用Python将选项传递给SeleniumChrome驱动程序。这可以借助ChromeOptions和DesiredCapabilities类的帮助。对于ChromeOptions,我们必须为该类创建一个对象。
然后,我们将借助add_argument方法的帮助,并将要发送给浏览器的选项作为该方法的参数传递。最后,必须将此信息提供给Web驱动程序。
示例
代码实现。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
#ChromeOptions的对象
op = webdriver.ChromeOptions()
#添加选项
op.add_argument('--enable-extensions')
#将选项传递给webdriver对象
driver = webdriver.Chrome(chrome_options=op)我们还可以借助DesiredCapabilities类添加功能。
代码实现。
#DesiredCapabilities的对象 c = webdriver.DesiredCapabilities.Chrome.copy() #将功能设置为True c['acceptInsecureCerts'] = True #将功能传递给webdriver对象 driver = webdriver.Chrome(desired_capabilities=c)
这样,我们可以通过Chrome选项。
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短