如何将多个扩展添加到硒铬网络驱动程序



如何为硒铬网络驱动程序添加多个扩展?

我尝试使用逗号添加扩展名,但出现错误

chrome_options.add_extension(r'C:UsersAdministratorDesktopchromedriver_win32extension.crx',r'C:UsersAdministratorDesktopchromedriver_win32extension1.crx',,r'C:UsersAdministratorDesktopchromedriver_win32extension3.crx')

但收到错误

我的工作代码有一个扩展:

import os
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import gmtime, strftime
from os import system
import pyperclip
import datetime
import time
import os
import sys

executable_path = r"C:UsersAdministratorDesktopchromedriver_win32chromedriver.exe"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension(r'C:UsersAdministratorDesktopchromedriver_win32extension.crx')
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
time.sleep(4)
driver.get("https://www.tradingview.com/chart/gK6Rq0UH/")
time.sleep(4)
driver.find_element_by_xpath("""//*[@id="footer-chart-panel"]/div[2]/span[4]""").click()
time.sleep(4)
while True:
    driver.find_element_by_xpath("""//*[@id="bottom-area"]/div[2]/div[1]/div[2]/ul/li[4]""").click()
    time.sleep(4)
    driver.switch_to_alert().accept()
    contents = pyperclip.paste()
    time.sleep(2)
    filepath = r"C:UsersAdministratorDesktopDATA.txt"
    time.sleep(2)
    with open(filepath, 'w') as f: # 'w' means write mode and we get the file object as f
        f.write(contents)

对于要添加的每个扩展,您必须像这样调用chrome_options.add_extension

chrome_options.add_extension('Path/to/extension/one')
chrome_options.add_extension('Path/to/extension/two')

相关内容

  • 没有找到相关文章

最新更新