View Single Post
Old 03-31-2023, 08:30 PM   #1
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 897
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Help with a code to get float data

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

Last edited by dunhill; 04-01-2023 at 04:23 PM.
dunhill is offline   Reply With Quote