尝试获取以下网址上的内容但不使用请求模块。虽然链接在浏览器上打开。如何使用请求库获取链接
success: function(model, response){
// Create a new Blob object using the
//response data of the onload object
var blob = new Blob([response], {type: 'text/csv'});
//Create a link element, hide it, direct
//it towards the blob, and then 'click' it programatically
let a = document.createElement("a");
a.style = "display: none";
document.body.appendChild(a);
//Create a DOMString representing the blob
//and point the link element towards it
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'Sample_report.csv';
//programatically click the link to trigger the download
a.click();
//release the reference to the file by revoking the Object URL
window.URL.revokeObjectURL(url);
}
答案 0 :(得分:1)
您正在尝试下载PDF。您可以使用 urllib2
执行此操作<强>示例强>
import urllib2
src_url = "http://www.dwconstir.com/inc/download.asp?FileName=3Q17%20%uC2E4%uC801PT_ENG.pdf"
path = "DEST_PATH" #Folder location where you want to download the file.
response = urllib2.urlopen(src_url)
file = open(path + "document.pdf", 'wb')
file.write(response.read())
file.close()
使用请求
import requests
url = 'http://www.dwconstir.com/inc/download.asp?FileName=3Q17%20%uC2E4%uC801PT_ENG.pdf'
path = "DEST_PATH" #Folder location where you want to download the file.
r = requests.get(url, stream=True)
with open(path + "document.pdf", 'wb') as f:
f.write(r.content)