Maciej Bliziński
unread,Sep 22, 2009, 6:06:04 AM9/22/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to beautifulsoup
Suppose I have a bit of HTML which looks like this: "<span>foo<!-- bar
--></span>". I want to extract the text contained within specific
tags, but without the commented-out text. Here, I'd like to extract
only "foo", without "bar".
>>> import BeautifulSoup as bs
>>> s = bs.BeautifulSoup("<span>foo<!-- bar --></span>")
>>> s.findAll()
[<span>foo<!-- bar --></span>]
This returns the whole <span/> tag, without stripping out the comment,
or returning the comment separately. Do you have any tips how to
extract only "foo" from the above HTML?
Maciej