I am trying to parse div block using Beautiful Soup
Which is
<div class="same-height-left" style="height: 20px;"><span class="value-frame"> whatever</span></div>
I want to get [what i expect]:
whatever
or <span class="value-frame"> whatever</span>
I tried
response = requests.get('http://example.com')
response.raise_for_status()
soup = bs4.BeautifulSoup(response.text)
div = soup.find('div', class_="same-height-left")
Result
None
And
soup = bs4.BeautifulSoup(response.text)
div = soup.find_all('div', class_="same-height-left")
Result
[]
How about this:
from bs4 import BeautifulSoup
html = """<div class="same-height-left" style="height: 20px;"><span class="value-frame"> whatever</span></div>"""
soup = BeautifulSoup(html, 'html.parser')
method1 = soup.find('div').text
method2 = soup.find('div').find('span').text
method3 = soup.find('span', class_='value-frame').text
print 'Result of method 1:' + method1 # prints " whatever"
print 'Result of method 2:' + method2 # prints " whatever"
print 'Result of method 3:' + method3 # prints " whatever"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With