Python Forum
Get latest version off website and save it as variable [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get latest version off website and save it as variable [SOLVED]
#6
import re
from collections import namedtuple

import bs4
import requests

MAKEMKV_BASE = "https://www.makemkv.com/download/"
VERSION_REG = re.compile(r"(\d+\.\d+\.\d+)")


def parse_version(file_name: str) -> str:
    if match := VERSION_REG.search(file_name):
        return match.group(1)
    else:
        return ""


MakeMKV = namedtuple("makemkv", "url version version_tuple os")


def get_makemv():
    content = requests.get(MAKEMKV_BASE).content
    doc = bs4.BeautifulSoup(content, "lxml")
    selector = "div#content > ul.bullets > li > a"
    for element in doc.select(selector, href=True):
        href = element["href"]
        if href.endswith(".txt"):
            continue

        version_str = parse_version(href)
        version_tuple = tuple(map(int, version_str.split(".")))
        name = element.text.lower()
        if "windows" in name:
            os_type = "windows"
        elif "mac os x" in name:
            os_type = "macos"
        else:
            os_type = "unkown"

        yield MakeMKV(href, version_str, version_tuple, os_type)


for result in get_makemv():
    print(result.os, result.version, result.url)
The inspector from Firefox helps a lot to find the elements.
I used this information to make the selector.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Get latest version off website and save it as variable - by DeaD_EyE - Nov-14-2021, 09:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 572 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  SOLVED variable as tuple name krayon70 7 1,874 Apr-09-2022, 03:30 PM
Last Post: krayon70
  How to save specific variable in for loop in to the database? ilknurg 1 1,166 Mar-09-2022, 10:32 PM
Last Post: cubangt
  [solved] subdictionaries path as variable paul18fr 4 2,680 May-18-2021, 08:12 AM
Last Post: DeaD_EyE
  [solved] Variable number of dictionnaries as argument in def() paul18fr 11 6,199 Apr-20-2021, 11:15 AM
Last Post: paul18fr
  Running latest Python version on the Terminal (MAC) Damian 4 2,661 Mar-22-2021, 07:58 AM
Last Post: Damian
  Latest file with a pattern produces an error tester_V 4 3,218 Dec-10-2020, 02:14 AM
Last Post: tester_V
  Read plotly-latest.min.js from local issac_n 1 2,193 Nov-18-2020, 02:08 PM
Last Post: issac_n
  How to save latest time stamp in a file? redwood 12 7,281 Jul-11-2019, 11:03 AM
Last Post: redwood
  Python ftp server get the latest sub-directory name muzamalrana 1 3,470 Aug-08-2018, 11:40 PM
Last Post: muzamalrana

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020