如何使用Selenium&安装Chrome扩展程序Python [英] How to install Chrome Extension using Selenium & Python
问题描述
你好,我正在尝试使用python使用Selenium安装Chrome扩展程序,我尝试使用
Hello I'm trying to install a Chrome extension with Selenium using python, I tried using ChromeDriver - WebDriver for Chrome
但是它不起作用,这是我的代码:
But it is not working, this is my code:
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import ChromeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import re # regular expressions, are imported from python directly
import time
import numpy as np
import pandas as pd
import functions_database
# Pandas read CSV
df_read = pd.read_csv(
'/home/daniel/amazon-project-scrapers/ss_scraper.edited2.csv')
amazon_data = list(df_read.amz_search)
# Chrome Driver + install plugin
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/home/daniel/amazon-project-scrapers/chromedriver_linux64/DS-Amazon-Quick-View_v2.8.9.crx"));
ChromeDriver driver = new ChromeDriver(options);
driver = webdriver.Chrome(executable_path='/home/daniel/amazon-project-scrapers/chromedriver_linux64/chromedriver')
driver.get('https://www.amazon.com/')
这是我得到的错误:
File "camel_scraper.py", line 23
ChromeOptions options = new ChromeOptions();
^
SyntaxError: invalid syntax
我尝试用其他3种不同的方式执行此操作,实际上在Stack Overflow中有一个类似的问题,其答案已被弃用,如果再次找到它,我将在此处编写链接.
I tried to do this in other 3 different ways, actually there is a similar question in Stack overflow whose answer is deprecated, if I find it again I'll write the link in here.
推荐答案
使用 python 客户端,您可以使用以下命令:
To add/install the DS-Amazon-Quick-View
Chrome extension using Selenium's python client you can use the following splution:
-
代码块:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension('/home/daniel/amazon-project-scrapers/chromedriver_linux64/DS-Amazon-Quick-View_v2.8.9.crx')
driver = webdriver.Chrome(options=chrome_options, executable_path='/path/to/chromedriver')
driver.get('https://www.google.co.in')
您可以在以下位置找到一些相关的讨论:
You can find a couple of relevant discussions in:
- [Python] 如何使用python在硒中的chrome驱动程序中加载扩展
- [Java] 如何在geckodriver中永久安装扩展
- [Python] How to load extension within chrome driver in selenium with python
- [Java] How to install extension permanently in geckodriver
这篇关于如何使用Selenium&安装Chrome扩展程序Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!