gpt4 book ai didi

python - 如何向 selenium chrome webdriver 添加多个扩展

转载 作者:行者123 更新时间:2023-12-01 02:03:33 24 4
gpt4 key购买 nike

如何向 selenium chrome webdriver 添加多个扩展?

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

chrome_options.add_extension(r'C:\Users\Administrator\Desktop\chromedriver_win32\extension.crx',r'C:\Users\Administrator\Desktop\chromedriver_win32\extension1.crx',,r'C:\Users\Administrator\Desktop\chromedriver_win32\extension3.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:\Users\Administrator\Desktop\chromedriver_win32\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension(r'C:\Users\Administrator\Desktop\chromedriver_win32\extension.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:\Users\Administrator\Desktop\DATA.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')

关于python - 如何向 selenium chrome webdriver 添加多个扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49311344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com