[Tutor] Problem with BeautifulSoup
Kent Johnson
kent37 at tds.net
Thu Sep 29 14:03:26 CEST 2005
(resending to the whole list)
Bernard Lebel wrote:
> 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....
I think that's right but I confess I don't understand that part of the code too well either. Maybe an email to the author? or maybe it's time to try ElementTree (and pdis XPath?) again.
Kent
>
>
> 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
>>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list