右键单击另存为动态href属性 [英] Right Click Save as on dynamic href attribute
本文介绍了右键单击另存为动态href属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网页,我在其中使用selenium
来自动下载文件.我可以导航到下载页面.我现在要做的就是右键单击并单击'save link as'
,然后单击"OK"
.
I have a webpage where I am using selenium
to automate downloading of a file. I am able to navigate to the download page. All I have to do now is right click and click on 'save link as'
and click "OK"
..
<tr>
<td class="orionSummaryHeader">
Export information:
</td>
<td class="orionSummaryColumn">
<a href="/core/cache/qcW2AaqeD-s22J6yOlx958EJN7w=/Exported_Systems.csv"target="_blank">Exported_Systems.csv</a><br>
</td>
</tr>
我尝试使用find_element_by_xpath()
,但仍然无法单击....
帮帮我!
I tried using find_element_by_xpath()
, but still not able to click....
Help me out!
推荐答案
您无需模拟右键单击即可保存链接.只需使用以下代码:
You don't have to simulate right-click to save link. Just use below code:
link = driver.find_element_by_link_text('Exported_Systems.csv').get_attribute('href')
如果要使用此链接下载文件,请尝试:
If you want to use this link to download file, try:
import requests
with open("/path/to/file.csv", "wb") as f:
f.write(requests.get(link).content)
这篇关于右键单击另存为动态href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文