Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: WWW::Mechanize and fooling server for javascript

by Cody Pendant (Prior)
on Jul 31, 2007 at 01:21 UTC ( [id://629721]=note: print w/replies, xml ) Need Help??


in reply to WWW::Mechanize and fooling server for javascript

Since Mech does not support javascript I do not get the whole page or the form for submitting the login.
That doesn't make any sense at all. No, Mech doesn't support JavaScript but neither does LWP. Unsurprisingly since they're really the same thing. But of course Mech gets the full page, it couldn't possibly function otherwise. print $mech->content(), without the format, will show you the source.

If you've got the source of the page, you can use it to find the Javascript. If you can find the JavaScript you can read it and find how it sets the data field.

And if you can bear to tell us what site you're trying to log into, this will get a lot easier because we'll be able to look at it as well.



Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

Replies are listed 'Best First'.
Re^2: WWW::Mechanize and fooling server for javascript
by gw1500se (Beadle) on Jul 31, 2007 at 12:04 UTC
    I thought I replied to this last night but I don't see it. My apologies if I am missing something and this turns out to be a double post.

    Thanks for the reply. I thought 'content' returned an HTML object if I didn't use the format. I'll give that a try.

    I agree that it seems impossible to not get the whole page but since this is my first time with Mech I don't really know all it does yet.

    The bottom line of this exercise is to get ALL the javascript source including that which comes as a link rather then embedded. That was the problem I was having with LWP, the 'GET' only gave me the source for embedded javascript.

    For a better description of what I am doing, please see the explanation in Using LWP to automate a login. I am trying to extract the assigned IP address from the ISP for a DSL line. To do that I need to log on to a D-Link EBR-2310 which will serve a status page containing that information. The trick is to authenticate to the router.
      gw1500se,

      Some routers use JavaScript to dynamically create an html page using document.write. As you have already been told LWP and WWW::Mechanize do not support JavaScript, see how to reboot adsl modem with perl? for a similar problem, and list of WWW::Mechanize variants that do support JavaScript.

      I don't know what you mean by 'fooling Server' but depending on the JavaScript in question it is often possible to write some Perl that provides the same function as the JavaScript does. If all you are looking for is the IP address assigned by your ISP, perhaps you could simply use WWW::Mechanize to get http://www.whatismyip.com (or similar service), and parse the response.

      Martin
        What I meant was that I initially thought there was some kind of redirect that prevented the full page from loading if javascript was not enabled. Thus the server would serve a different page unless javascript was enabled. I was looking for a way to fool that mechanism into thinking javascript was enabled.

        I have since been convinced this is not possible so my only alternative is to be able to parse the javascript for the assignment I am looking for (data='some hash string'). I am finding that the challenge is to find something that will let me access the javascript source. It seems that if the javascript is a link rather then embedded, LWP at least, will not "GET" it. I am hoping Mech will when I try it without the format option.

Log In?
Username:
Password:

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

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

    No recent polls found