[Greasemonkey] How can I get the content of Comment section in a
HTML page?
esquifit
esquifit at googlemail.com
Tue Sep 12 15:03:07 EDT 2006
You can access HTML comments via XPath indeed. Assuming your document is
<?xml version="1.0" ?>
<people>
<person id="1">
<name>Pete Freitag</name>
</person>
<person id="2">
<!--This is an HMTL comment-->
<name>Dude</name>
</person>
</people>
then /people/name/comment() gives a nodeset consisting of all the comment
nodes directly under "names" under "people". In this case, the node
value is the string "This is an HMTL comment". Similarly, //comment() finds
all the comments in the document (except those contained in the document
type declaration, but those are unlikely to be useful for anything).
There are other (more involved) ways to get at the comment nodes, for
instance through treewalkers; I make use of this technique in a couple of
scripts to detect ads (surrounded by "begin/end ads" comments) in a more
robust way than merely hard-coding the XPath like in "/a[3]/span/[4]/...".
2006/9/11, Mark F. Liu <marklf at tom.com>:
>
> Hi! This is my first use of this mailing list.
>
> I need to use the comment(e.g. thouse string around '<!' and '>') in a
> HTML page.
>
> I have tried and failed to use both XPth and getelementbytagname().
>
> Could you please help me to get it?
>
> Thanks.
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list