如何使用Selenium和Python安装Chrome扩展程序

发布于 2021-01-29 18:21:28

您好,我尝试使用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中有一个类似的问题,其答案已被弃用,如果再次找到它,我将在此处编写链接。

关注者
0
被浏览
142
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    DS-Amazon-Quick-View使用的python客户端添加/安装Chrome扩展程序,可以使用以下示例:

    • 代码块:

      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')



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看