Indeed this is weird. When I run your code, I get the Google consent modal, and an error

2 elements found for //body at pb11123357.pl line 13.

... most likely because there are two body elements, one in the consent modal iframe and one in the main page.

Once I click that away, I get the script content of the page, because the contents of script tags are also included in the textContent attribute. This is somewhat inconvenient, and I see no easy workaround for this. The fix seems to be to use the innerText attribute instead of textContent. Making this change makes the page "work" in the sense that the <script> content is not printed anymore. As a workaround you can monkey-patch the code until the next release:

use WWW::Mechanize::Chrome; { no warnings 'redefine'; sub WWW::Mechanize::Chrome::text { my $self = shift; # Waugh - this is highly inefficient but conveniently short to wri +te # Maybe this should skip SCRIPT nodes... join '', map { $_->get_attribute('innerText') } $self->xpath('//bo +dy', single => 1 ); } }

Thanks for reporting this! If this works for you as well, I'll write a test for this and release the fix soonish.


In reply to Re^3: Retrieve Rendered Web Page Using WWW::Mechanize::Chrome by Corion
in thread Retrieve Rendered Web Page Using WWW::Mechanize::Chrome by roho

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.