Skip to content Skip to sidebar Skip to footer

Using Beautiful Soup To Get Data From Non-class Section

I am still very novice and learning python and beautiful soup. I have gotten hung up on how to get text from a non-class piece of HTML. This is the snippet of HTML I'm working w

Solution 1:

Well you can do the following, taking into consideration that s is the html string:

from bs4 import BeautifulSoup

soup = BeautifulSoup(s)
print soup.find(attrs={'id' : 'postingbody'})

Output:

<sectionid="postingbody">
            some posting info
            <br/>
             more posting info
             <br/></section>

Solution 2:

In addition to Games Brainiac's answer: To get the text just put .text behind it.

So:

print soup.find(attrs={'id' : 'postingbody'}).text

Solution 3:

If you are using BeautifulSoup4, you do it like this:

element = soup.find(id="postingbody")

Post a Comment for "Using Beautiful Soup To Get Data From Non-class Section"