Python beautiful soup arguments

Posted by scott on Stack Overflow See other posts from Stack Overflow or by scott
Published on 2010-04-03T12:22:48Z Indexed on 2010/04/03 12:33 UTC
Read the original article Hit count: 296

Filed under:
|

Hi

I have this code that fetches some text from a page using BeautifulSoup

soup= BeautifulSoup(html)
body = soup.find('div' , {'id':'body'})
print body

I would like to make this as a reusable function that takes in some htmltext and the tags to match it like the following

def parse(html, atrs):
 soup= BeautifulSoup(html)
 body = soup.find(atrs)
 return body

But if i make a call like this

    parse(htmlpage, ('div' , {'id':'body'}"))  or like

parse(htmlpage, ['div' , {'id':'body'}"])

I get only the div element, the body attribute seems to get ignored.

Is there a way to fix this?

© Stack Overflow or respective owner

Related posts about python

Related posts about beautifulsoup