简体   繁体   English

chromeOptions.add_experimental_option没有这样的属性

[英]chromeOptions.add_experimental_option no such attribute

I wish to do a direct download of a PDF and not display in Chrome's pdf view plugin The Python code I found is 我希望直接下载PDF,而不显示在Chrome的pdf视图插件中。我找到的Python代码是

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]}
chromeOptions.add_experimental_option("prefs",prefs)
driver=webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', chrome_options=chromeOptions)

chromeOptions does not have an add_experimental_option function/methodP. chromeOptions没有add_experimental_option函数/ methodP。 Is there a way to make this work please. 有没有一种方法可以使这项工作。

Here is the proper way to initialize chrome options: 这是初始化chrome选项的正确方法:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()

I believe that is your issue. 我相信那是你的问题。 I tested this code and it worked for me: 我测试了这段代码,它为我工作:

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

chrome_options = Options()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]}
chrome_options.add_experimental_option("prefs",prefs)
driver=webdriver.Chrome(chrome_options=chrome_options)

For more information you can read the docs here regarding the Chrome WebDriver API for Selenium 有关更多信息,您可以在此处阅读有关适用于Selenium的Chrome WebDriver API的文档

For whatever reason the method add_experimental_option does not appear. 无论出于何种原因,都不会出现方法add_experimental_option。 Possibly this is because I am using a Linux install. 可能是因为我正在使用Linux安装。 My goal is to download a series of PDFs automatically. 我的目标是自动下载一系列PDF。 A work around is to first get the PDF in the pdf-viewer by finding a web element with the click() command. 一种解决方法是,首先使用click()命令找到一个Web元素,以在pdf查看器中获取PDF。 this loads the PDF into the viewer, then read the contents of the URL bar, the use the PDF address to make a call to the Linux operating system running the dowload command "wget" to obtain the PDF file. 这会将PDF加载到查看器中,然后读取URL栏的内容,使用PDF地址调用运行dowload命令“ wget”的Linux操作系统来获取PDF文件。 That is: 那是:

driver.find_element_by_class_name('browzine-direct-to-pdf-link').click()
pdfAddress=driver.current_url
os.system("wget %s -P /home/keir/Downloads/pdfs" % pdfAddress)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Options().add_experimental_option 不起作用 - Options().add_experimental_option does not work Selenium chrome 使用多个 add_experimental_option - Selenium chrome use multiple add_experimental_option 如何在 python selenium webdriver chrome 中添加多个实验选项? - How to add multiple experimental option in python selenium webdriver chrome? Selenium + Python + Chrome:同时添加_experimental_option并设置期望的功能 - Selenium + Python + Chrome: simultaneously add_experimental_option and set desired_capabilities selenium.webdriver.chrome.webdriver' 在 Python Robotframework 中没有属性 'ChromeOptions - selenium.webdriver.chrome.webdriver' has no attribute 'ChromeOptions in Python Robotframework 模块 'keras.layers' 没有属性 'experimental' - module 'keras.layers' has no attribute 'experimental' AttributeError: 'Options' 对象没有属性 'self' 错误,使用 ChromeOptions for headless Google Chromethrough Selenium Python - AttributeError: 'Options' object has no attribute 'self' error using ChromeOptions for headless Google Chromethrough Selenium Python 使用Selenium ChromeDriver中的ChromeOptions和通过Python的Chrome,“选项”对象没有属性“ set_preference”错误 - 'Options' object has no attribute 'set_preference' error using ChromeOptions in Selenium ChromeDriver and Chrome through Python ArgumentParser对象在传递标志时没有属性“ add_option” - ArgumentParser object has no attribute 'add_option' on passing flags 无法解析功能:来自无效参数的 goog:chromeOptions:无法识别的 chrome 选项:prefs - cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: prefs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM