Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^7: WWW::Mechanize::Firefox and dynamic pages

by Special_K (Monk)
on Jul 30, 2013 at 05:50 UTC ( [id://1046948]=note: print w/replies, xml ) Need Help??


in reply to Re^6: WWW::Mechanize::Firefox and dynamic pages
in thread WWW::Mechanize::Firefox and dynamic pages

Does it matter that the link I'm trying to capture from the page with my script resides inside of an iframe? It looks like this in firebug:

<iframe id="iframe_canvas" class="smart_sizing_iframe" scrolling="yes" + height="800" frameborder="0" msallowfullscreen="" oallowfullscreen=" +" mozallowfullscreen="" webkitallowfullscreen="" src="javascript:""" +name="iframe_canvas_fb_https" style="height: 472px;"> <html> <head> <body> <div> <a href="link I'm trying to capture"</a> </div> </body> </head> </html> </iframe>

I already have this in my perl code:

$mech->allow(plugins => 1, javascript => 1, metaredirects => 1, frames + => 1, subframes => 1, images => 1);

So it seems like all iframes should be processed correctly, right?

Replies are listed 'Best First'.
Re^8: WWW::Mechanize::Firefox and dynamic pages
by Corion (Patriarch) on Jul 30, 2013 at 07:08 UTC

    Yes, it does matter. ->content never looks inside iframe elements.

Re^8: WWW::Mechanize::Firefox and dynamic pages
by Special_K (Monk) on Aug 01, 2013 at 03:18 UTC

    Is there a way to make

    content()

    look into frames? I added this to my code:

    my @frames = $mech->expand_frames(); my $frame_ctr = 0; for ($frame_ctr = 0; $frame_ctr < @frames; $frame_ctr++) { printf("frames[%s] = %s\n", $frame_ctr, $frames[$frame_ctr]); }

    But I'm not really sure what to do with the frames that were returned.

      What you get back are DOM nodes. You can access their attributes. For example, the innerHTML attribute:

      print $frame->{innerHTML}

      By doing that, you've mostly left the area that WWW::Mechanize::Firefox supports and you will have to consult the Firefox documentation for what attributes and methods are supported.

        Just because I hate finding questions online with no resolution, I'm coming back with the answer. Here is how I was able to find the link I was looking for within the page's HTML:

        my @test_frames = $mech->xpath('/html/body/div/p/a', one => 1, frames +=> 1); printf(TEST_FH "result is %s\n", $test_frames[0]->{outerHTML});

        I obtained the xpath using Firebug (highlight the link on the webpage, right click, select "copy Xpath") then used the outerHTML (as opposed to innerHTML) to get the URL.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1046948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found