V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
millet230413
V2EX  ›  GitHub

关于 github 文件下载的问题

  •  
  •   millet230413 · Feb 7, 2024 · 3226 views
    This topic created in 810 days ago, the information mentioned may be changed or developed.

    我通过 wget 或者 curl 到 github 上面下载一个源文件,我用浏览器点击直接下载,下载到的是正常的源文件,但是使用 wget / curl 下载到的就是一个 json 文件,这个 json 文件里面描述了我要下载的文件。即使使用 copy permalink 获取到的下载链接,用 wget / curl 下载下来的也是 json 描述文件,而不是源文件本身。

    请问我要如何使用 wget / curl 到 github 下载源文件呢

    10 replies    2024-02-07 21:58:56 +08:00
    Rnreck
        2
    Rnreck  
       Feb 7, 2024
    @Alias4ck #1 400: Invalid request
    Alias4ck
        3
    Alias4ck  
       Feb 7, 2024
    4ark
        4
    4ark  
       Feb 7, 2024 via iPhone
    页面有个链接可以直接打开 raw 的,保存就是了
    fioncat
        5
    fioncat  
       Feb 7, 2024
    把你链接里面的 github.com 域名换成 raw.githubusercontent.com

    PS. 该域名在国内经常存在 DNS 污染的问题,建议挂梯子使用。
    hukei
        6
    hukei  
       Feb 7, 2024
    应该见过很多分享的一键执行脚本用的这个地址的吧 raw.githubusercontent.com
    Rnreck
        7
    Rnreck  
       Feb 7, 2024
    @Alias4ck #3 抱歉,一开始确实没仔细看,直接点进去了,然后根据 return 回复你了,那是实在有点不清醒,非常抱歉,,,,后面又试了一下 curl 能用,wget 显示 Unable to establish SSL connection. 这个情况,更新下 openssl 搞定了
    henix
        8
    henix  
       Feb 7, 2024
    beyondstars
        9
    beyondstars  
       Feb 7, 2024   ❤️ 1
    您好,加一个 'Accept' 参数即可:

    curl -L -H 'accept: application/vnd.github.raw' https://api.github.com/repos/fivethirtyeight/data/contents/ahca-polls/ahca_polls.csv
    beyondstars
        10
    beyondstars  
       Feb 7, 2024   ❤️ 1
    对于不同的 accept 参数值,可以获取到不同的格式。参见 github api doc 对 media types 的定义: https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api?apiVersion=2022-11-28#media-types
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3360 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 00:34 · PVG 08:34 · LAX 17:34 · JFK 20:34
    ♥ Do have faith in what you're doing.