[英]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.