"Argument is type NoneType" even though I can print it

"Argument is type NoneType" even though I can print it

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())

Answer

This part isn't an actual answer, however, since I don't have 50 reputation yet, I can't add a comment. I think the most recent answer (besides mine) is obviously, so obviously an AI - generated answer, so could someone please flag user20275214's answer? Examples of AI: 'Without seeing the code', 'assistance', these are all stupid. The code has been provided, and it is very clear that you didn't paste the code in. ;-;

You should try converting the 'None' type into a string object, if you haven't already, or debugging it by printing it out at some steps.

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles