Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading file with Python mechanize

I am trying to download a file from a website using python and mechanize. My current code successfully logs on to the website and opens the page that contains the download link.

The download link is: https://www.lendingclub.com/browse/browseNotesRawDataV2.action

The info for the link is:

Link(base_url='https://www.lendingclub.com/browse/browse.action', url='/browse/browseNotesRawDataV2.action', text='', tag='a', attrs=[('class', 'master_pngfix'), ('id', 'browseDownloadAllLink'), ('href', '/browse/browseNotesRawDataV2.action')])

I use the follow_link method to click on the link:

br = mechanize.Browser()
br.follow_link(url='/browse/browseNotesRawDataV2.action')

However, nothing happens and no file is downloaded. When I open the link in my browser when I'm logged on, it pauses for a few seconds and downloads the file.

How can I download the file using Python?

like image 306
user1137778 Avatar asked Jun 12 '12 17:06

user1137778


1 Answers

For anyone who's interested, this was the solution:

br.retrieve('https://www.lendingclub.com/browse/browseNotesRawDataV2.action','l‌​oans.csv')[0]
like image 182
user1137778 Avatar answered Oct 08 '22 18:10

user1137778