View Single Post
Old 04-01-2023, 09:15 AM   #2
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,220
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
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 is offline   Reply With Quote