[Python] How to use Python to download a pdf file from a link (not button!)

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    How to use python to download a pdf file from a "Download PDF" link on a web page and save it to a local folder? If I move cursor to the link and right click "inspect" I got following html for this link:

    <a class="cmp-utility-button" href="/content/dam/xxxxxx/en/app-notes/2004/720000999/720000999-en.pdf" target="_blank" title="Download PDF" data-di-id="di-id-31c755d1-a112c01b">
    <span>Download PDF </span>


    But this is NOT a button for you to click and download pdf file directly. It's a link that when you click it, it opens the pdf file with a url like this:

    https://www.xxxxxx.com/content/dam/xxxxxx/en/app-notes/2004/720000999/720000999-en.pdf

    On this opened pdf file page, you can use a download button on right upper corner (next to that "printer" icon for printing) to download it.

    I have a script that works well for a "download" button. But a few things I tried all failed for the pages using this kind of links for pdf files. Any code examples are appreciated. In python script I should assume I only know original html web page with the link, not the url of the pdf file ( but we can use href if needed), and I need to loop through hundreds of web pages. Thanks.

    Continue reading...

Compartilhe esta Página