Given following HTML:

<div id="CID60" class="calendar"> <div> <h2 class="">City Council Subcommittee</h2> </div> <ol class=""> <li class=""> <h3> <a id="eventTitle_2941" href="" onclick="eventDetails(2941, +3, 4, 2016, 0); return false;" name="eventTitle_2941"><span class=""> City Council Sub-Committee Legislative and Ordinance Commi +ttee</span> </a> </h3> <a href="/Calendar.aspx?EID=2941&amp;day=3&amp;month=4&amp;yea +r=2016&amp;calType=0" class=""> More Details </a> </li> <li class=""> <h3> <a id="eventTitle_2921" href="" onclick="eventDetails(2921, +3, 4, 2016, 0); return false;" name= "eventTitle_2921"><span class="" +> City Council Sub-Committee Personnel Action Committee</spa +n> </a> </h3> <a href="/Calendar.aspx?EID=2921&amp;day=3&amp;month=4&amp;yea +r=2016&amp;calType=0" class=""> More Details </a> </li> </ol> </div>

I'm trying to extract the href values for the two links with a text of "More Details" using the xpath method. Here's the code I'm using to do that:

my @links = $mech->xpath('//div[@id=\'CID60\']/ol/li/a/@href', type => + $mech->xpathResult('STRING_TYPE', all => 1)); print Dumper(\@links);

This is what gets returned:

$VAR1 = [ '/Calendar.aspx?EID=2941&day=3&month=4&year=2016&calType=0', '' ];

I'm not sure why the second value is empty. This xpath tester says my xpath argument should work fine.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to Having trouble getting WWW::Mechanize::Firefox->xpath to return expected results by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.