Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest release version in Github only use python-requests?

Recently,I make an app and upload it to my GitHub release page.I want to make a function to check update to get the latest version(in the release pages).

I try to use requests module to crawl my release page to get the latest version.Here it a minimal example of my code:

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)

I think the xpath is right,because I use chrome -> copy -> copy xpath.But it return me a [].it can't find the latest version.

like image 961
Kevin Mayo Avatar asked Mar 17 '20 03:03

Kevin Mayo


People also ask

How do I pull latest release from GitHub?

On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases. To copy a unique URL to your clipboard, find the release you want to link to, right click the title, and copy the URL. Alternatively, right click Latest Release and copy the URL to share it.

How do I get python code from GitHub?

On GitHub, navigate to the main page of the repository. Click the Clone or download button located under the repository name. A dropdown is displayed. Click on Download ZIP and save the repository as a zip file to your system.

What is new release in GitHub?

Releases are GitHub's way of packaging and providing software to your users. You can think of it as a replacement to using downloads to provide software. It replaces since July 2013 an old "GitHub Download" system which was beginning to get abused (people stored anything and everything in it), and removed in Dec. 2012.

What is Target_commitish?

target_commitish. string. Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists.

What is a GitHub release?

GitHub Releases are a great resource for open source projects to expand on the simple git tag concept. You can add release notes in Markdown format, and you can upload finalized assets – such as compiled executables. As a user I had the question – how do I script "download the latest release, please?"

Why does the setup-Python action download a specific version of Python?

If a specific version of Python is not pre-installed in the tools cache, the setup-python action will download and set up the appropriate version from the python-versions repository.

What version of Python is installed on Ubuntu?

Ubuntu runners have multiple versions of system Python installed under /usr/bin/python and /usr/bin/python3. The Python versions that come packaged with Ubuntu are in addition to the versions that GitHub installs in the tools cache.

How do I use Python with GitHub actions?

Using the setup-python action is the recommended way of using Python with GitHub Actions because it ensures consistent behavior across different runners and different versions of Python. If you are using a self-hosted runner, you must install Python and add it to PATH. For more information, see the setup-python action.


1 Answers

A direct way is to use GitHub API, it is easy to do and don't need xpath.


The URL should be:

https://api.github.com/repos/{owner}/{repo}/releases/latest

So if you want to get the latest release version of the repository. Here is an easy example only using the requests module:

import requests

response = requests.get("https://api.github.com/repos/v2ray/v2ray-core/releases/latest")
print(response.json()["name"])
like image 109
jizhihaoSAMA Avatar answered Sep 20 '22 19:09

jizhihaoSAMA