使用Python机械化下载文件 [英] Downloading file with Python mechanize

查看:75
本文介绍了使用Python机械化下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python从网站下载文件并进行机械化.我当前的代码成功登录到网站,并打开包含下载链接的页面.

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.

下载链接为: https://www.lendingclub.com/browse/browseNotesRawDataV2.action

该链接的信息为:

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')])

我使用follow_link方法单击链接:

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.

如何使用Python下载文件?

How can I download the file using Python?

推荐答案

对于有兴趣的人,这是解决方案:

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

br.retrieve('https://www.lendingclub.com/browse/browseNotesRawDataV2.action','l‌​oans.csv')[0]

这篇关于使用Python机械化下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆