Çağdaş Salur
Çağdaş Salur

Reputation: 1390

Python Downloading a file without having a direct link on mechanize

After i connect to a website and get the neccessary url's at the last one the downloading automatically triggers and chrome starts to download the file.

Howewer in mechanize this doesnt seems to work;

br.click_link(link)
br.retrieve(link.base_url, '~/Documents/test.mp3')

I only get a 7kb *.mp3 file on my document folder which holds the html data in it.

Here's the link i am working on: http://www.mrtzcmp3.net/Ok4PxQ0.mrtzcmp3 It may go bad after few minutes but basically when i click the url in chrome i get the mp3 fila automatically.

Upvotes: 0

Views: 1941

Answers (1)

Çağdaş Salur
Çağdaş Salur

Reputation: 1390

I woke up today and tried this;

link = [l for l in br.links()][-1]
br.click_link(link)
response = br.follow_link(link)
open('asd.mp3', 'w').write(response.read())

for anyone with the same problem, that works.

Upvotes: 1

Related Questions