【问题标题】:CasperJS - downloading generated file with no URLCasperJS - 下载没有 URL 的生成文件
【发布时间】:2015-02-24 18:33:32
【问题描述】:

我已经为此苦苦挣扎了一段时间。

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

有没有办法在没有 URL 的情况下保存该资源?

我找到了这个解决方法:downloading a file that comes as an attachment in a POST request response in PhantomJs

但不幸的是,Google Adwords 报告按钮没有我可以参考的表单。

【问题讨论】:

标签: javascript csv download phantomjs casperjs


【解决方案1】:

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

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

表单数据:

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

请求标头:

: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}}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 2022-01-01
    相关资源
    最近更新 更多