我正在尝试从具有身份验证的网站下载文件。我想出了如何下载该文件,但它会保存在 %PROFILE\appdata\local\temp\ 目录中,名称类似于 tmpxhq6u1.mobi。如何使用另一个文件名将其保存到另一个位置?
from mechanize import Browser
USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv:1.8.1.9) Gecko/20071102 Pardus/2007 Firefox/2.0.0.9"
br = Browser()
br.addheaders = [("User-agent", USER_AGENT)]
br.open("https://login.nrc.nl/login?service=http://digitaleeditie.nrc.nl/digitaleeditie/")
br.select_form(nr=0)
br['username'] = "XXXXXXX"
br['password'] = "xxxxxxx"
# br['rememberMe'] = ["1"]
response = br.submit()
print response.read()
f = br.retrieve('http://digitaleeditie.nrc.nl/digitaleeditie/helekrant/mobipocket/nn_20120521.mobi')[0]
print f