TypeError: 'str' object is not callable for scraping data from a webstie

I would like to print the price of something on a website every second but I get the error "TypeError: ‘str’ object is not callable"

Here is my code:

import requests
from bs4 import BeautifulSoup
import time

url = "https://www.roblox.com/catalog/20573078/Shaggy"
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
newprice = soup.find("span", {"class": "text-robux-lg wait-for-i18n-format-render"}).text
a = 1

while a == 1:
    time.sleep(1)
    print(newprice())

>Solution :

You are printing a function, not the variable. Simply just use:

print(newprice)

Output:

enter image description here

EDIT:

The price you are scraping won’t update because you have already put the information in that variable. In order to achieve what you are wanting you will need to scrape in the loop as well, like so:

url = "https://www.roblox.com/catalog/20573078/Shaggy"
a = 1

while a == 1:
    soup = BeautifulSoup(requests.get(url).content, 'html.parser')
    newprice = soup.find("span", {"class": "text-robux-lg wait-for-i18n-format-render"}).text
    time.sleep(1)
    print(newprice)

This will make it so every time that while loop is ran it gets the data from the website.

Leave a Reply