How to find latest version number of python from web?

Question:

I’m looking for getting latest version of python.

For example, I can find latest version of golang at https://go.dev/VERSION?m=text

Is there same thing as golang?

Asked By: edp1096

||

Answers:

This may not be the best way to do it but you can interrogate the latest downloadable with this:

import requests
from bs4 import BeautifulSoup

(r := requests.get('https://www.python.org/downloads/')).raise_for_status()
soup = BeautifulSoup(r.text, 'lxml')
if (a := soup.find_all('a', class_='button')):
    print(a[0].text.split()[-1])

Output:

3.10.7
Answered By: Vlad
$url = "https://www.python.org/downloads"
$doc = (Invoke-Webrequest $url).ParsedHTML # mshtml.HTMLDocumentClass
$as = $doc.Links

foreach($a in $as) {
    if ($el.className -eq "button") {
        Write-Output $el.innerText.split(" ")[-1] | Out-File -FilePath PYTHON_VERSION -encoding ASCII
        # Write-Output $el.innerText.split(" ")[-1]> "PYTHON_VERSION"
        break
    }
}

Like answer which I accepted, also it is possible to use powershell or sh, but this is not I want to do.

Unlike Go, the long live python never care these trivial things.

It make me sad.

Answered By: edp1096
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.