04-01-2023, 04:20 PM
|
#3
|
Guru
Posts: 894
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Quote:
Originally Posted by thiago.eec
Hi, @dunhill
Maybe I'm wrong, but I think you may have translated your original code to Spanish and then back to English. This caused some problem with python syntax getting changed, like 'try' to 'attempt'.
Here is a working code, returning a 'float':
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(pricebox) == 1:
for p in pricebox:
pricerange = p.find(class_="price")
return float(pricerange.text.replace('$', '').replace('.','').replace(',' , '.'))
else:
return none
except:
return none
P.S.: ISBN here is assumed to be a string, so I didn't change this.
|
thiago.eec
Thanks for the code.
Works !!
Last edited by dunhill; 04-01-2023 at 04:49 PM.
|
|
|