Limiting search to a comment-delimited section of the document?

3 views
Skip to first unread message

Xif Q

unread,
Apr 18, 2008, 6:42:57 PM4/18/08
to BeautifulSoup mailing group
Hi,

A document contains a section delimited by comments. How do you tell BeautifulSoup to limit searches to that section only?

To illustrate, the document looks like this:

<!--START-->
[...
this is the relevant section of the document. we want to perform searches that would search only here
...]
<!--END-->

How is this to be done with BeautifulSoup?

I was thinking about getting the indexes of the comments in the original string of the document, then getting just the relevant substring and making just that into a BeautifulSoup.BeautifulSoup instance.

But aside from this method being very ugly (the resulting substring would contain shards of broken elements etc.), I can't find the way to get the index of a BeautifulSoup.NavigableString.

Thanks for any pointers,

Xif
Reply all
Reply to author
Forward
0 new messages