I want to modify some data obtained by a plugin that they made for me and I don't want to be too upset with the programmer who has so kindly done it.
The original code includes the price in text format. With this parameter(pricespan.text)
I am looking to get the data in decimal format ( float ) as seen in the code replacement but I don't get the result. If someone can give me a hand.
Don't laugh at me if I replaced the wrong code
This is the original code:
Code:
def scrape (isbn):
from bs4 import BeautifulSoup as bs
import requests
url = "https://www.tematika.com/catalogsearch/result/?q=" + isbn
r = requests.get(url)
soup = bs(r.text, 'html.parser')
div = soup.find(id='jm-current-content')
try:
pricebox = div.find_all(class_="price-box")
if len(price box) == 1:
for p in pricebox:
price range = p.find(class_="price")
return pricespan.text
the rest:
return none
except:
return none
And I have changed it to this:
Code:
def scrape (isbn):
from bs4 import BeautifulSoup as bs
import requests
url = "https://www.tematika.com/catalogsearch/result/?q=" + isbn
r = requests.get(url)
soup = bs(r.text, 'html.parser')
div = soup.find(id='jm-current-content')
try:
pricebox = div.find_all(class_="price-box")
if len(price box) == 1:
for p in pricebox:
price range = p.find(class_="price")
return float((pricespan.text).replace('.','').replace(',' , '.'))
the rest:
return none
except:
return none