Possible Duplicate:
How to download a text file or some objects from webpage using Python?
I am trying to download a file under “Pre-Release Domains” from this website: http://www.namejet.com/pages/downloads.aspx
So as today is 10th of October you want to get the file “Wednesday, October 10, 2012”.
When the click on the file the link doesn’t changes so I have trouble writing python code to download the particular file as I don’t have the specific URL of particular file. How do I write the script? I want everything to happen in the back end without actually opening the browser:
#!/usr/bin/python
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()
browser=webdriver.Firefox() # Select browser that you want to automate
browser.get('http://www.namejet.com/pages/downloads.aspx')
element=browser.find_element_by_xpath(
'//a[@id="ctl00_ContentPlaceHolder1_hlPreRelease1"]')
element.click()
display.stop()
This code runs without error but doesn’t downloads the file. What am I doing wrong?
Now you can find prerelease_10-08-2012.txt in your download folder and you can open it in a usual way.
EDIT: note that the code downoads the latest file, that is prerelease_10-10-2012.txt as for today. Just tried it and it works fine.