0

I am trying to download a folder from our university system with python where the link is created on click.

<li onclick="return il.BgTask.init('ilFolderDownloadBackgroundTaskHandler', 1607834);;">
<a id="act_1607834_pref_1576848_" href="#"><span class="xsmall">Download</span></a>
</li>

As far as I understand it there is some JS performing onclick which is generating the download link. I tried to find a GET Request in the Network tab to see what happens but without success. It seems like that when I click on "Download Folder" the folder first gets zipped serverside and then served as a download to me.

Is there any workaround or solution for this to get the exact download link or to perform the required actions to create one and get it in python?

tymz96
  • 1

1 Answers1

0

when you press the link you are actually running the following javascript function: il.BgTask.init('ilFolderDownloadBackgroundTaskHandler', 1607834);

try to use selenium's javascript injection to have the browser run the function and download the file.

michmich112
  • 744
  • 4
  • 8
  • Thanks for the input. Selenium is requiring to have a browser opened, right? So it is not possible to run this as a script only in the background from the terminal for example. – tymz96 Mar 30 '20 at 23:13
  • @tymz96 use `requests_html` which will render the `JavaScript` on the fly. – αԋɱҽԃ αмєяιcαη Mar 30 '20 at 23:16
  • @tymz96 yes selenium does require to have a browser and a webdriver for that browser. The advantage is that you're able to run any function that is proper to that page and that it exposes (this function in this case) it'll be like you pressed the button yourself. You will be able to run it in the terminal but it will open an instance of the browser. The workaround is to run it in headless mode which wont open a browser and you'll be able to "run it as a script". – michmich112 Mar 30 '20 at 23:48
  • Thanks both. I guess this is what I am looking for https://stackoverflow.com/questions/26393231/using-python-requests-with-javascript-pages/54056631#54056631 – tymz96 Mar 31 '20 at 08:25