python - 如何使用 Selenium 和 Python 安装 Chrome 扩展
问题描述
您好,我正在尝试使用 python 使用 Selenium 安装 Chrome 扩展,我尝试使用ChromeDriver - WebDriver for Chrome
但它不起作用,这是我的代码:
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 中有一个类似的问题,其答案已被弃用,如果我再次找到它,我会在这里写下链接。
解决方案
要使用Selenium的python客户端添加/安装DS-Amazon-Quick-View
Chrome 扩展,您可以使用以下 splution:
代码块:
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')
参考
您可以在以下位置找到一些相关的讨论:
推荐阅读
- typescript - 事件监听器参考打字稿函数
- xamarin - 如何将 Xamarin.Forms 上的 3D 安全与 Stripe 集成?
- github - GitHub 同步未反映我的 Visual Studio 2019 项目的文件和文件夹结构
- javascript - ReactJS Json 对象数组
- delphi - 键值更改后刷新查找字段值
- javascript - 如何让我的搜索栏工作,以便它可以调用多个变量
- ios - 主应用程序无法引用 React Native Library 中使用的框架
- dynamics-crm - PowerApps - 我在 CDS 中创建实体的许可要求是什么?
- javascript - 结合角度路径参数?
- django - Django重新同步自动增量pk与恢复的数据库