Solution 1 :

You basically had it, just needed to use the attrs dictionary for the correct div class and then searched for the next ‘br’ tag, whose sibling is your text:

from bs4 import BeautifulSoup as bs
HTML = """
<div class="col search_price discounted responsive_secondrow">
<span style="color: #888888;"><strike>CDN$ 2.29</strike></span>
<br>CDN$ 1.48
</div>
"""
soup = bs(HTML, 'html.parser')
# get all divs with your class attr
divs = soup.find_all("div", attrs={'class': 'col search_price discounted responsive_secondrow'})
for div in divs:
    # find the <br> tag, next_sibling is the data
    print(div.find_next('br').next_sibling)

Solution 2 :

Other solutions.

from simplified_scrapy.simplified_doc import SimplifiedDoc
html='''
<div class="col search_price discounted responsive_secondrow">
<span style="color: #888888;"><strike>CDN$ 2.29</strike></span>
<br>CDN$ 1.48
</div>
'''
doc = SimplifiedDoc(html)
divs = doc.getElementsByClass('col search_price discounted responsive_secondrow')
for div in divs:
  value = div.br.nextText() # first
  print (value)
  value = doc.html[div.br._end:div._end-6] # second
  print (value)
  value = doc.removeHtml(div.getSectionByReg('<br.*>.*')) # third
  print (value)
  value = div.removeElement('span') # fourth
  print (value.text)

Result:

CDN$ 1.48
CDN$ 1.48
CDN$ 1.48
CDN$ 1.48

Problem :

This is my HTML tag. I am trying to get the value after the <br> tag. When I try to do it I get both the values. How would I do this using Beautiful Soup. Any help would be appreciated.

<div class="col search_price discounted responsive_secondrow">
<span style="color: #888888;"><strike>CDN$ 2.29</strike></span>
<br>CDN$ 1.48
</div>

Comments

Comment posted by Tammo Heeren

What have you tried? Show your code.

Comment posted by Rohan Afsan

js_soup.find_all("div", class_="col search_discount responsive_secondrow")

Comment posted by Rohan Afsan

js_soup.find_all("strike",)

Comment posted by Rohan Afsan

But I need the value in

Comment posted by Tammo Heeren

maybe lxml and xpath could be an option. Beautifulsoup might not do what you want.

By