Home > Software engineering >  Find Method Data-Bind tag within HTML with Beautiful Soup
Find Method Data-Bind tag within HTML with Beautiful Soup

Time:08-01

I am having trouble in selecting this 'data-bind' object in Beautiful Soup and then parsing the data within. This method hasn't any data-bind finder like class or id ext.

I need just little text "2.179". How can I get this text.

<span  itemprop="price" data-bind="css: {'merchant': !isHepsiburadaProduct(), 'hepsiburada': isHepsiburadaProduct(), 'price-new-old': product().currentListing.pricing.listingPriceList.length === 1, 'price-new': product().currentListing.pricing.listingPriceList[product().currentListing.pricing.listingPriceList.length - 1].discountRate > 0}" id="offering-price" content="2179.00">
                    <span data-bind="markupText:'currentPriceBeforePoint'">2.179</span>,<span data-bind="markupText:'currentPriceAfterPoint'">00</span>
                    <span  itemprop="priceCurrency" content="TRY">TL</span>
                    <span  style="font-weight: normal; font-size: 16px; color: #646464; " data-bind="css: {hidden: unitPriceFormatted() == ''}, html:unitPriceFormatted()"></span>
                </span>

CodePudding user response:

IIUC, The content 2.179 is not present under data-bind. You can select span tag then get the text of its first child.

soup.select_one('#offering-price span:first-child').text

will give you

'2.179'
  • Related