Reputation: 9501
I am having a problem and not sure if this is possible at all, so if someone could point me in the right direction.
I need to open a file from a webpage, open it in excel and save the file.
The problem I am running into the file name on the website has a file name ( not an active link ) and then it will have a "download " button that is not specific to the file I need to download. So instead of the download button being "file1todaysdate", they are nothing that I could use from day to day.
Is there a way I could locate file name then grab the file from the download icon? then save in excel? If not sorry for wasting time.
Upvotes: 2
Views: 1206
Reputation: 56813
When you press Download, where the file actually coming from? Get that download link first. If it is hard to detect from the browser, use a tool like firebug to get the download link. Once you got it. You can use Python to dowload it using urllib.urlretrieve
filename, msg = urllib.urlretrieve('http://yourlinktodownload/file.xls')
The filename will point to the file which was downloaded. If it xls format, it should open in excell.
Upvotes: 2
Reputation: 174614
I think what you are asking is how to search a web page for some text that is not a link, request that link, save the file.
BeautifulSoup is normally used for this.
However, requests is another library you can use to fetch the page and then grab the contents for later analysis.
Upvotes: 2
Reputation: 798526
Examine the Content-Disposition
header of the response to discover what the server wants you to call the file.
Upvotes: 0