代码之家  ›  专栏  ›  技术社区  ›  Kevin Mayo Pavel Krčmář

如何在Github中获得只使用python请求的最新版本?

  •  1
  • Kevin Mayo Pavel Krčmář  · 技术社区  · 6 年前

    我试着用 requests

    import requests
    from lxml import etree
    
    response = requests.get("https://github.com/v2ray/v2ray-core/releases")
    html = etree.HTML(response.text)
    Version = html.xpath("/html/body/div[4]/div/main/div[3]/div/div[2]/div[1]/div/div[2]/div[1]/div/div/a")
    print(Version)
    

    我认为xpath是正确的,因为我使用 chrome -> copy -> copy xpath [] 。找不到最新版本。

    1 回复  |  直到 6 年前
        1
  •  2
  •   jizhihaoSAMA    6 年前

    直接的方法是使用 Github API ,很容易做到,不需要使用xpath。

    因此,如果您想获得存储库的最新版本 requests 模块:

    import requests
    
    response = requests.get("https://api.github.com/repos/v2ray/v2ray-core/releases/latest")
    print(response.json()["name"])