BeautifulSoup: get contents[] as a single string

Anyone know an elegant way to get the entire contents of a soup object as a single string?

At the moment I'm getting contents, which is of course a list, and then iterating over it:

notices = soup.find("div", {"class" : "middlecontent"})
con = ""
for content in notices.contents:
    con += str(content)
print con

Thanks!

19
задан AP257 20 December 2010 в 10:39
поделиться