[Tutor] Problem with BeautifulSoup

Bernard Lebel 3dbernard at gmail.com
Thu Sep 29 03:25:36 CEST 2005


Hi Kent,

Thanks a lot for that answer. I have had a look at the BS code, and I
have to admit I'm a bit at a loss: how would you add several nestable
tag names in that list?

I tried
NESTABLE_TAGS = BeautifulSoup.buildTagMap( [], 'parameter', 'parameters' )
for example, but I kept having these nesting issues. I fact I have a
whole bunch of tags that I need to make nestable....


Thanks
Bernard


On 9/26/05, Kent Johnson <kent37 at tds.net> wrote:
> Bernard Lebel wrote:
> > Hi grouchy,
> >
> > I seem to have found the problem. Somehow, it seems BeautifulSoup
> > doesn't like nested tags of the same name.
>
> This seems to be a feature of BS. It seems a bit of a misfeature when applied to XML but anyway...you can configure BS with a set of tags which can be nested, then it will properly parse your data. Here is a short program that shows how:
>
> xml = '''<parameter scriptname="posx">
>     <fcurve plotted="False">
>           <parameter scriptname="extrapolation">1</parameter>
>     </fcurve>
> </parameter>'''
>
> import BeautifulSoup
>
> class NestingParser(BeautifulSoup.BeautifulStoneSoup):
>     NESTABLE_TAGS = BeautifulSoup.buildTagMap([], 'parameter')
>
> soup = NestingParser(xml)
> print soup.prettify()
>
>
> Kent
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list