Issue
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.
Solution
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"])
Answered By - jizhihaoSAMA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.