Hm. So neither of them actually leaves the original untouched, I just
happened to have a fully-escaped link in my test case, so I didn't
realize it would have escaped it otherwise when calling str().
Well, darn. Unfortunately I don't see an elegant way around this.
I'll look at trying something semi-kludgy. Maybe a regex...I realize
those are horrible for HTML (I tried them before discovering the
difficulties), but I'm looking for a very particular type of string
that is very consistent. (I'm trying very hard to leave the rest of
the document untouched, so running a replace on all the escaped
entities in the entire document isn't going to work. Plus, that would
break any XHTML compliance.)
I realize that BeautifulSoup is mainly used to clean up bad HTML, so
maybe this isn't a common enough use case to justify changes. In
fact, what I'm trying to do might go against the whole philosophy
behind BeautifulSoup (which I respect as a very nice, useful tool).
However, I might as well ask: how hard would it be to create an
extract-only mode that doesn't modify any of the original document,
but could parse it and then find and return certain elements
(unmodified)?
Perhaps a better question: do you know of any robust HTML parsers
written in Python that already do this?