Create a string array of all comments in a html file...

Paul McGuire ptmcg at austin.rr.com
Sun Sep 30 16:49:41 EDT 2007


On Sep 30, 10:39 am, sophie_newbie <paulgeele... at gmail.com> wrote:
> Hi, I'm wondering how i'd go about extracting a string array of all
> comments in a HTML file, HTML comments obviously taking the format
> "<!-- Comment text here -->".
>
> I'm fairly stumped on how to do this? Maybe using regular expressions?
>
> Thanks.

>>> from pyparsing import htmlComment
>>> htmlComment.searchString("""<!-- Comment
... here -->And <i>so</i> funny!
... </p><!-- Comment <> -->""").asList()
[['<!-- Comment \nhere -->'], ['<!-- Comment <> -->']]

-- Paul






More information about the Python-list mailing list