我有这样的代码,获取使用BeautifulSoupPython的美丽汤参数
从页面中的一些文本soup= BeautifulSoup(html)
body = soup.find('div' , {'id':'body'})
print body
我想使这是一个可重复使用的函数,它在一定的htmlText和与之相匹配的,如标签以下
def parse(html, atrs):
soup= BeautifulSoup(html)
body = soup.find(atrs)
return body
但是,如果我作出这样
parse(htmlpage, ('div' , {'id':'body'}")) or like
parse(htmlpage, ['div' , {'id':'body'}"])
我只得到div元素的电话, body属性似乎被忽略。
有没有办法解决这个问题?
感谢您的回答,它的工作。我不知道可以使用*解压列表,认为只有使用* \ *的字典可以工作。 – scott 2010-04-03 12:37:01
@scott:阅读文章Mark在他的回答中链接到 – 2010-04-03 12:43:55
@EliBendersky太棒了!但任何想法如何我们可以解压一个单一的字典密钥(如“班”在'del标签[“类”]')? http://stackoverflow.com/questions/41792761/calling-and-using-an-attribute-stored-in-variable-using-beautifulsoup-4 – JinSnow 2017-02-02 21:22:31