我想使用带有扩展的python selemium隐姓埋名,但到目前为止都不起作用有人能搞定吗?
我试过了:
options.add_extension('plugin.crx')
#options.add_argument("--incognito")
#options.add_argument("user-data-dir=C:\Users\Maxva\AppData\Local\Google\Chrome\User Data\Profile 9")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
#driver.get('chrome://extensions/?id=lncaoejhfdpcafpkkcddpjnhnodcajfg')
#driver.execute_script("return document.querySelector('extensions-manager').shadowRoot.querySelector('#viewManager > extensions-detail-view.active').shadowRoot.querySelector('div#container.page-container > div.page-content > div#options-section extensions-toggle-row#allow-incognito').shadowRoot.querySelector('label#label input').click()")
我最喜欢的技巧是使用键盘:
options.add_argument("--incognito")
options.add_extension('Google-Translate.crx')
driver.get("chrome://extensions")
time.sleep(1)
action = ActionChains(driver)
# Open the extension:
for _ in range(2):
action.send_keys(Keys.TAB).perform()
action.send_keys(Keys.RETURN).perform()
# Flip the switch that enables it in incognito
for _ in range(4):
action.send_keys(Keys.TAB).perform()
action.send_keys(Keys.RETURN).perform()