Jacobm001
Jacobm001

Reputation: 4549

Beautiful Soup and improper lists

I'm trying to pull data out of a crappy application that stores its data in HTML. I have a section of code that looks like this:

<span id="blah">
  item 1 <br />
  item 2 <br />
  item 3 <br />
</span>

I can find the data with beautiful soup, but when I use the .text operator, it returns the contents as item 1item 2item 3.

Any ideas on how to get it where
is returned as '\n' so I can break it up by lines?

Upvotes: 0

Views: 50

Answers (1)

Amber
Amber

Reputation: 527173

You can use .strings to get all of the separate text items within an element (or .stripped_strings to have surrounding whitespace automatically stripped from each).

http://www.crummy.com/software/BeautifulSoup/bs4/doc/#strings-and-stripped-strings

Upvotes: 2

Related Questions