【问题标题】:CURL Get download link from request and download fileCURL 从请求和下载文件中获取下载链接
【发布时间】:2018-11-24 05:53:25
【问题描述】:

我正在使用 conversocial API: https://api-docs.conversocial.com/1.1/reports/

使用文档中的示例,因为经过所有调整后我收到了这个“输出”

{
    "report": {
        "name": "dump", "generation_start_date": "2012-05-30T17:09:40",
        "url": "https://api.conversocial.com/v1.1/reports/5067",
        "date_from": "2012-05-21",
        "generated_by": {
            "url": "https://api.conversocial.com/v1.1/moderators/11599",
            "id": "11599"
        },
        "generated_date": "2012-05-30T17:09:41",
        "channel": {
            "url": "https://api.conversocial.com/v1.1/channels/387",
            "id": "387"
        },
        "date_to": "2012-05-28",
        "download": "https://s3.amazonaws.com/conversocial/reports/70c68360-1234/@twitter-from-may-21-2012-to-may-28-2012.zip",
        "id": "5067"
    }
}

目前,我可以将此 JSON 输出排序为仅下载,并将接收此输出

{
   "report" : {
      "download" : "https://s3.amazonaws.com/conversocial/reports/70c68360-1234/@twitter-from-may-21-2012-to-may-28-2012.zip"
   }
}

是否通过使用 CURL 来自动化这个过程,让 curl 下载这个文件?

要下载我打算使用简单的方法:

curl URL_LINK > FILEPATH/EXAMPLE.ZIP

目前在想有没有办法将 URL_LINK 替换为下载链接??或者任何其他方式,方法,方式????

【问题讨论】:

    标签: json api curl git-bash


    【解决方案1】:

    试试这个:

    curl $(curl -s https://httpbin.org/get | jq ".url" -r) > file
    

    只需根据您的 json 替换您的 urljq 参数,可能是:

    jq ".report.download" -r
    

    -r 将删除双引号 "

    它的工作方式是使用command substitution $()

    $(curl -s https://httpbin.org/get | jq ".url" -r)
    

    这将获取您的 URL 并使用 jq 从返回的 JSON 中提取新 URL,稍后将其作为参数传递给 curl。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2014-05-18
    相关资源
    最近更新 更多