[Python] "Argument is type NoneType" even though I can print it

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

  1. Stack

    Stack Membro Participativo

    Every time I run the script it says:

    'NoneType' object has no attribute 'get_text.


    Every time I run the script without the .get_text (on the price section), the two .replace (on first and second) and the float() (in floatprice) lines in each function it just runs smoothly.

    import requests
    from bs4 import BeautifulSoup
    import sys

    #input del prodotto da monitorare
    print("[1] Amazon product")
    print("[2] Ebay product")

    option = int(input("Select the service:"))

    if option != 0:
    if option == 1:

    option1ver1 = input("Enter your Amazon link: ")

    def price_extraction_amazon():
    #Scraping della pagina web
    r = requests.get(option1ver1)
    text = BeautifulSoup(r.text, 'html.parser')
    price = text.find('span', class_='aok-offscreen').get_text()
    first = price.replace("€", "")
    second = first.replace(",", ".")
    floatprice = float(second)
    return first

    price_extraction_amazon()
    print(price_extraction_amazon())

    elif option == 2:

    option1ver2 = input("Enter your Ebay link: ")

    def price_extraction_ebay():
    #Scraping della pagina web
    r = requests.get(option1ver2)
    text = BeautifulSoup(r.text, 'html.parser')
    price = text.find('span', class_='ux-textspans').get_text()
    first = price.replace("EUR ", "")
    second = first.replace(",", ".")
    floatprice = float(second)
    return floatprice

    price_extraction_ebay()
    print(price_extraction_ebay())

    else:
    sys.exit("Wrong selection")

    else:
    sys.exit("Wrong selection")

    option2 = float(input("enter the price threshold: "))
    floor_price = option2


    I expect it to print the price number that it got from the original Amazon/EBay page without EUR /€ and as a float.

    This is the section of the code that is causing me problems with translated comments:

    option1ver1 = input("Enter your Amazon link: ")

    def price_extraction_amazon():
    #Scraping of the web page
    r = requests.get(option1ver1)
    text = BeautifulSoup(r.text, 'html.parser')
    price = text.find('span', class_='aok-offscreen').get_text()
    first = price.replace("€", "")
    second = first.replace(",", ".")
    floatprice = float(second)
    return floatprice

    #prints the price
    price_extraction_amazon()
    print(price_extraction_amazon())

    Continue reading...

Compartilhe esta Página