70599

想在 PageSpeed Release Notes 中提取最新的版本号,自己想了一个很笨的,求一个更直接的

  •  
  •   70599 · Oct 1, 2016 · 2520 views
    This topic created in 3520 days ago, the information mentioned may be changed or developed.

    下面是我自己写的,怎样更简洁一些?

    curl -sL https://developers.google.com/speed/pagespeed/module/release_notes | egrep -o "id=\"release_[0-9.]+" | egrep -o "[0-9.]+" | head -n 1
    
    7 replies    2016-10-01 22:14:34 +08:00
    ldbC5uTBj11yaeh5
        1
    ldbC5uTBj11yaeh5  
       Oct 1, 2016   ❤️ 1
    grep 这两句可以合成一个

    curl -sL https://developers.google.com/speed/pagespeed/module/release_notes | grep -oP "id=\"release_\K[0-9.]+" | head -1
    ldbC5uTBj11yaeh5
        2
    ldbC5uTBj11yaeh5  
       Oct 1, 2016
    哦,看了下文档, grep -m 1 还可以省掉 head -1 这个命令了。
    70599
        3
    70599  
    OP
       Oct 1, 2016
    感谢🙏
    70599
        4
    70599  
    OP
       Oct 1, 2016
    因为狗发威阿里云上根本打不开 Release Notes 😂
    wdlth
        5
    wdlth  
       Oct 1, 2016
    70599
        6
    70599  
    OP
       Oct 1, 2016
    @wdlth 没用过。请问怎样在 shell 里获取版本号?也是 curl 下来 grep 吗?

    我现在用的是
    ```
    curl -sL https://github.com/pagespeed/ngx_pagespeed/releases | grep -oP "tag-name\">v\K[0-9.]+" -m 1
    ```
    wdlth
        7
    wdlth  
       Oct 1, 2016
    @70599 GitHub API 返回的是 JSON ,你可以用 python 或者其他工具进行解析。

    比如用 Python 进行解析

    curl -sL https://api.github.com/repos/pagespeed/mod_pagespeed/tags | python -c "import sys, json; print json.load(sys.stdin)[3]['name']"

    一般来说应该是排在前面的,但 Google 放了几个没版本号的在前面,你也可以进行判断。
    API 的格式相对是不变的,但网页的话可能会改版,也可能触发一些 WAF 防御规则,禁止非正常访问,看你自己选择。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2876 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:03 · PVG 23:03 · LAX 08:03 · JFK 11:03
    ♥ Do have faith in what you're doing.