I had been using www::mechanize::firefox to extract hidden html from a javascript heavy website but mozrepl no longer works for more recent versions of firefox

I thought I could use www::mechanize::phantomjs in a similar way but I'm struggling to get it to find the elements and extract the inner html from xpath

The long xpath in the code below should be getting all the html in:

<div class="tn-napsTable">

This same code worked well in mechanize::firefox but when i run it with PhantomJS I get the error message 'no elements found'. Any help would be much appreciated!

use strict; use WWW::Mechanize::PhantomJS; use Data::Dumper; my $mech = WWW::Mechanize::PhantomJS->new( launch_arg => ['ghostdriver/src/main.js' ], ); $mech->get('https://www.racingpost.com/tipping/naps-table/'); sleep 5; my $cont= $mech->xpath('/html/body/div[4]/main/div/div[2]/div/div/div[ +2]/div/div[1]/div[1]/div[2]', one => 1,synchronize=>1); my $content=$cont->{innerHTML}; print $content;

In reply to No Elements Found with WWW::Mechanize::PhantomJS by rmperl

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.