Ghost.py
Ghost.py copied to clipboard
How to download file by clicking on download button?
I'm trying to download a file by clicking on a download link but I can't get it to work. I also see other people struggling with downloading files. I'm trying it using this code:
from time import sleep
from ghost import Ghost
with ghost.start as session:
page, extra_resources = session.open('http://hkramer.nl/opslag/zommel/tstest.html')
session.click('#downloadzip')
print page.http_status
print page.content
sleep(5) # wait for the zip file to be downloaded
print session.http_resources
But this only prints:
200
<html>
<body>
<a id="downloadzip" href="test.zip">downloadzip</a>
</body>
</html>
[]
Does anybody know how I can download any files? All tips are welcome! I'd be happy to throw in some money for the solution!
Hi :) Try to add the parameter expect_loading to True (you can see in the file ghost.py that the click function have the can_load_page decorator).
page, extra_resources = session.click('#downloadzip', expect_loading=True)
With this you will be able to get the content of the file