A
A
AlexCruel2020-08-07 11:07:15
beautiful soup
AlexCruel, 2020-08-07 11:07:15

BeautifulSoup - problem extracting numbers with comma?

Example: you need to parse the price of 39.90, but the output is 39. Cuts off everything after the decimal point.

from bs4 import BeautifulSoup
import requests

def parse():
    URL = 'https://1ak.by/shop/masla/motornye-masla/dlya-legkovyh-avtomobilej/gazpromneft-super-5w-40.html'
    HEADERS = {
        'Accept': '*/*',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
    }

    response = requests.get(URL, headers=HEADERS)
    soup = BeautifulSoup(response.content, 'html.parser')
    item = soup.find('div', class_='page-product__basket__total').find('b', class_='js-ch-cart-total').get_text(strip=True)

    print(item)

parse()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-07
@AlexCruel

Because in js-ch-cart-total 39, not 39.90
Most likely js is then fixed to 39.90, so parse either through selenium, or look for another tag, for example

<input type="hidden" name="product_price" class="js-ch-product-price gec-product-price" value="39,9">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question