[Python] Why does BeautifulSoup in Python give me an unexpected output?

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am extremely new to Python and web scraping. I want to build a simple script for checking the NVIDIA driver page for new versions from time to time using the code below.

    from bs4 import BeautifulSoup
    import requests

    url = "https://www.nvidia.com/en-us/drivers/"
    response = requests.get(url)
    soup = BeautifulSoup(response.content, "html.parser")

    # Find the version number (572.83)
    version_number = soup.find('td', class_='version').text
    print(f"Defined version number: {version_number}")

    # Check if the correct version number is present
    expected_version = "572.83"
    if version_number != expected_version:
    print(f"Warning: Incorrect version ({version_number}) found instead of {expected_version}")


    I expected to get the following outputs running this script:

    Defined version number: 572.83


    When I run the script I get the following outputs:

    Defined version number: ~ddVersion_td~
    Warning: Incorrect version (~ddVersion_td~) found instead of 572.83


    Can anyone shed some light on what I am missing? I have scrubbed through a few different forums and the documentation but I haven't been able to dedicate much time to it.

    Continue reading...

Compartilhe esta Página