相关疑难解决方法(0)

如何在selenium中使用chrome webdriver在python中下载文件?

根据这里这里的帖子,我试图在selenium中使用chrome webdriver来下载文件.这是迄今为止的代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_experimental_option("profile.default_content_settings.popups", 0)
chrome_options.add_experimental_option("download.prompt_for_download", "false")
chrome_options.add_experimental_option("download.default_directory", "/tmp")

driver = webdriver.Chrome(chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)

但仅这一点会导致以下错误:

WebDriverException: Message: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: download.default_directory
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.10.0-37-generic x86_64)
Run Code Online (Sandbox Code Playgroud)

那么如何解决这个问题呢?我必须使用这种"能力"的东西吗?如果是这样,怎么样?

python selenium google-chrome

14
推荐指数
3
解决办法
3万
查看次数

什么是python相当于useAutomationExtension for selenium?

我正在尝试从我的办公室环境运行一个基本的selenium脚本,它具有代理和防火墙设置.该脚本运行正常,但在每次执行之前它都会弹出一个提示"管理员禁用解压缩扩展的加载".这意味着我必须手动点击它才能继续,这违背了自动化的目的. 在此输入图像描述

我用谷歌搜索并堆栈溢出错误,看起来有一个需要禁用的chrome选项useAutomationExtension.我去了蟒蛇搜索正确的语法(环境:Python的2.7-win32的,运行Chrome司机2.30.477700(0057494ad8732195794a7b32078424f92a5fce41)),但找不到合适的镀铬开关/选项.

我也看了这个:铬/ Chrome会从谷歌开关:https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc 和CHROM开关彼得的名单:https://开头彼得.SH /实验/铬的命令行开关/

我模糊地试过chrome_options.add_argument(' - disable-useAutomationExtension'),但这也没有帮助.

所以,我需要你的指导和建议.请帮忙.

Code_part:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re, os

from selenium.webdriver.chrome.options import Options


class Sel(unittest.TestCase):
    def setUp(self):
        # self.driver = webdriver.Firefox()

        # Clean existing file before starting
        #############################################
        dlpath = "C:\Users\Baba\blacksheep_tracker.xlsm"

        if os.path.exists(dlpath):
            os.remove(dlpath)

        ############################################

        chrome_options = Options()
        chrome_options.add_argument("--cipher-suite-blacklist=0x0039,0x0033")
        chrome_options.add_argument("--disable-extensions")
        chrome_options.add_argument('--start-maximized')
        chrome_options.add_argument('--disable-useAutomationExtension')
        self.driver = webdriver.Chrome(chrome_options=chrome_options)

        self.driver.implicitly_wait(30)
        self.base_url …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

4
推荐指数
2
解决办法
4138
查看次数