简体   繁体   English

需要使用 python selenium 下载 PDF

[英]need to download a PDF using python selenium

i am trying to automate PDF downloading using Selenium Webdriver in python我正在尝试在 python 中使用 Selenium Webdriver 自动下载 PDF

but the problem is the download button was hidden inside a embed tag in HTML但问题是下载按钮隐藏在 HTML 的嵌入标签中

<embed width="100%" height="100%" name="plugin" id="plugin" src="www.abc.com/123.pdf" type="application/pdf" internalinstanceid="4" title="">

and the page would be like this page view before download button view并且页面在下载按钮视图之前会像这个页面视图

if i move the mouse over the top of the PDF如果我将鼠标移到 PDF 的顶部

after i move the mouse button over the top of the PDF在我将鼠标按钮移到 PDF 顶部之后

i need to click on the download button but the element was not visible at first when i try to inspect its element by clicking f12 but when i inpect the element by right clickin on it, it will load the new separate HTML document so i have no idea how to manipulate into that HTML any idea would be very helpful.我需要单击下载按钮,但是当我尝试通过单击 f12 检查其元素时,该元素起初不可见,但是当我通过右键单击该元素来检查该元素时,它将加载新的单独 HTML 文档,因此我没有想法如何操纵该 HTML 任何想法都会非常有帮助。

Why are you using Selenium for this?你为什么要为此使用硒?

It is easy and efficient with Requests.使用 Requests 既简单又高效。

import requests
url='https://www.cs.uky.edu/~keen/115/Haltermanpythonbook.pdf'
page = requests.get(url) # get url

name = url.split('/')[-1] # to get filename
f = open(name,'wb')  # make a file object

f.write(page.content) # write data
f.close()

This gives you flexibility to download anywhere you want and is a lot faster than selenium.这使您可以灵活地在任何地方下载,并且比 selenium 快得多。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM