Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I prefer using XPath expressions when I can, for much the same reason that I prefer using regular expressions to building my own pastern matching code. To get the same results as your DOM code I would use the following.

    var result = document.evaluate(
        '//tr[td[last()=2]][td[1]/text()="Links"]/td[2]',
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null
    );
    for (var i = 0; i < result.snapshotLength; i++) {
        add_links(result.

    • I think that using it in a userscript is safe though.

      Yes, it’s Firefox (and maybe Opera) only, which supports XPath.

      so I would not use it in general purpose code

      Indeed; in general purpose code you would use jQuery (or some other DOM query library of your preference) to write the same thing with CSS3 selectors. This particular case is not as concise as the XPath version because it needs to check text content, which CSS largely has no means to do.

      For comparison’s sake, if written in jQu