Access Tag via beautifulsoup

0

Hello, I'm having trouble accessing the price that is in the third line of the code via beautifulsoup.

Does anyone have any idea how to access?

                                             

    <span id="ctl00_Conteudo_ctl01_spanPrecoPor" class="for">
        <span id="ctl00_Conteudo_ctl01_lblPrecoPor">Por:</span>
        <strong id="ctl00_Conteudo_ctl01_precoPorValue">R$<i class="sale price">6.099,00</i></strong>

        <span id="ctl00_Conteudo_ctl01_comDescontoPlus" class="discountTxtPlus"></span>
    </span>
    <span id="ctl00_Conteudo_ctl01_spanParcel" class="parcel">ou até <strong>12x</strong> de <strong> R$508,25</strong> sem juros</span> 
    <span id="ctl00_Conteudo_ctl01_spanSave" class="save">
        <span id="ctl00_Conteudo_ctl01_lblEconomize"></span>
        <strong id="ctl00_Conteudo_ctl01_valorEconomize"></strong>
    </span>

    <span id="ctl00_Conteudo_ctl01_spanPrecoFull" class="for full">
        <span id="ctl00_Conteudo_ctl01_lblPrecoFull"></span>
        <strong id="ctl00_Conteudo_ctl01_precoFullValue"></strong>
    </span>

    <span id="ctl00_Conteudo_ctl01_spanParcelFull"></span>
    <span id="ctl00_Conteudo_ctl01_spanSaveFull" class="save full" style="display: none">
        <span id="ctl00_Conteudo_ctl01_lblEconomizeFull"></span>
        <strong id="ctl00_Conteudo_ctl01_valorEconomizeFull"></strong>
    </span>


</span>

I'm using the function below after the name but not the price:

def data_list (url):

browser = webdriver.Chrome()
urlDado = url
browser.get(urlDado)
innerHTML = browser.execute_script("return document.body.innerHTML")
browser.close()

soupDados = BeautifulSoup(innerHTML, 'lxml')

produtoNome = soupDados.b.string
produtoPreco = soupDados.find('span', {'strong':'id'})

d = {
    'Nome Produto':produtoNome,
    'Preco':produtoPreco,
    'teste':'teste'
    }
#print(soupDados.prettify())
print(d)

return d
    
asked by anonymous 05.12.2018 / 14:49

1 answer

0

Just search for class sale price and get your content

# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup

data = """<span id="ctl00_Conteudo_ctl01_spanPrecoPor" class="for">
        <span id="ctl00_Conteudo_ctl01_lblPrecoPor">Por:</span>
        <strong id="ctl00_Conteudo_ctl01_precoPorValue">R$<i class="sale price">6.099,00</i></strong>

        <span id="ctl00_Conteudo_ctl01_comDescontoPlus" class="discountTxtPlus"></span>
    </span>
    <span id="ctl00_Conteudo_ctl01_spanParcel" class="parcel">ou até <strong>12x</strong> de <strong> R$508,25</strong> sem juros</span> 
    <span id="ctl00_Conteudo_ctl01_spanSave" class="save">
        <span id="ctl00_Conteudo_ctl01_lblEconomize"></span>
        <strong id="ctl00_Conteudo_ctl01_valorEconomize"></strong>
    </span>

    <span id="ctl00_Conteudo_ctl01_spanPrecoFull" class="for full">
        <span id="ctl00_Conteudo_ctl01_lblPrecoFull"></span>
        <strong id="ctl00_Conteudo_ctl01_precoFullValue"></strong>
    </span>

    <span id="ctl00_Conteudo_ctl01_spanParcelFull"></span>
    <span id="ctl00_Conteudo_ctl01_spanSaveFull" class="save full" style="display: none">
        <span id="ctl00_Conteudo_ctl01_lblEconomizeFull"></span>
        <strong id="ctl00_Conteudo_ctl01_valorEconomizeFull"></strong>
    </span>   
</span>"""

soup = BeautifulSoup(data)

div = soup.find('i', class_='sale price')

print div.text

Result

6,099.00

    
27.12.2018 / 18:38