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&day=3&month=4&yea +r=2016&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&day=3&month=4&yea +r=2016&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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |