下载生成的没有URL的文件

时间:2023-02-05 09:56:17

I have been struggling with this one for a while.

我已经为这个问题挣扎了一段时间了。

I am trying to download CSV file generated by Google Adwords "download report" button. I can click the link just fine and see the resource in the background. The problem is that in order to download it, casperJS/phantomJS requires a URL to the file... but the CSV is generated on the spot and has the same URL as the page I am on (following that link just leads you to the homepage, not the CSV file so casperJS can't download it).

我正在尝试下载由谷歌Adwords“下载报告”按钮生成的CSV文件。我可以很好地点击链接,在后台看到资源。问题是,为了下载它,casperJS/phantomJS需要一个文件的URL……但是CSV是当场生成的,并且具有与我所访问的页面相同的URL(链接后面的链接只指向主页,而不是CSV文件,所以casperJS无法下载)。

Is there a way to save that resource without the URL?

是否有一种方法可以在没有URL的情况下保存该资源?

I found this workaround: downloading a file that comes as an attachment in a POST request response in PhantomJs

我找到了一种变通方法:下载一个文件,该文件以PhantomJs中的POST请求响应作为附件

But unfortunately, Google Adwords report button has no form that I can reference.

但不幸的是,谷歌Adwords report按钮没有我可以引用的表单。

1 个解决方案

#1


1  

I did a simple request analysis with chrome developer tools: The download request goes (for me) to the following URL:

我用chrome开发工具做了一个简单的请求分析:下载请求(对我来说)到以下URL:

Request URL:https://adwords.google.com/reports/advanced/ReportDownload?authuser=0

Formdata:

Formdata:

__rds:{{censored}}
__rrd:{{censored}}
__u:{{censored}}
__c:{{censored}}
__rfl:8,9,10
token:{{censored}}:{{censored}}

Request Headers:

请求头信息:

:authority:adwords.google.com
:method:POST
:path:/reports/advanced/ReportDownload?authuser=0
:scheme:https
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/ *;q=0.8
accept-encoding:gzip, deflate
accept-language:en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4,hr;q=0.2,sr;q=0.2
cache-control:max-age=0
content-length:501
content-type:application/x-www-form-urlencoded
cookie: {{censored}}
dnt:1
origin:https://adwords.google.com
referer:https://adwords.google.com/reports/advanced/AdvancedReporting?__c={{censored}}&__u={{censored}}&authuser=0&__o=cues
upgrade-insecure-requests:1
user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
x-client-data:{{censored}}

I have removed data potentially specific to me by replacing it with the {{censored}} tag.

我已经删除了可能特定于我的数据,将其替换为{{删除}标签。

#1


1  

I did a simple request analysis with chrome developer tools: The download request goes (for me) to the following URL:

我用chrome开发工具做了一个简单的请求分析:下载请求(对我来说)到以下URL:

Request URL:https://adwords.google.com/reports/advanced/ReportDownload?authuser=0

Formdata:

Formdata:

__rds:{{censored}}
__rrd:{{censored}}
__u:{{censored}}
__c:{{censored}}
__rfl:8,9,10
token:{{censored}}:{{censored}}

Request Headers:

请求头信息:

:authority:adwords.google.com
:method:POST
:path:/reports/advanced/ReportDownload?authuser=0
:scheme:https
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/ *;q=0.8
accept-encoding:gzip, deflate
accept-language:en-US,en;q=0.8,de-DE;q=0.6,de;q=0.4,hr;q=0.2,sr;q=0.2
cache-control:max-age=0
content-length:501
content-type:application/x-www-form-urlencoded
cookie: {{censored}}
dnt:1
origin:https://adwords.google.com
referer:https://adwords.google.com/reports/advanced/AdvancedReporting?__c={{censored}}&__u={{censored}}&authuser=0&__o=cues
upgrade-insecure-requests:1
user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
x-client-data:{{censored}}

I have removed data potentially specific to me by replacing it with the {{censored}} tag.

我已经删除了可能特定于我的数据,将其替换为{{删除}标签。