右键单击Dynamic HREF属性上的另存



我有一个网页,我在其中使用 selenium自动下载文件。我可以导航到下载页面。我现在要做的就是右键单击,然后单击'save link as',然后单击"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(),但仍然无法单击。帮帮我!

您不必模拟右键单击即可保存链接。只需使用以下代码:

link = driver.find_element_by_link_text('Exported_Systems.csv').get_attribute('href')

如果要使用此链接进行下载文件,请尝试:

import requests
with open("/path/to/file.csv", "wb") as f:
    f.write(requests.get(link).content)

最新更新