Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading