in reply to Converting Javascript to Perl

It sounds like you are trying to automate what would happen if you went to a URL (at teenopendiary) and clicked delete note (am I following you so far?)

First let me say that Javascript (which is not the same thing as Java BTW) is most likely not your problem. To delete a note that resides on their server they'll be using some sort of client side language (ASP it looks like) where Javascript is client side and can't do anything to the server.

What you need to do is find out the specific request created to delete an item from that site. If they use a GET request then just delete something and copy the URL that appears. This is what you want. Then use the LWP::Simple module (should be in your standard Perl) to recreate the request.

Of course its probably not going to be that easy :). My guess is that teenopendiary has some kind of security measure in place that involves cookies or sessions and most likely uses POST requests. For those you'll probably need to use the full LWP module (also should be in Perl but if not you can get it from CPAN). I'm not going to go in depth on how to do it right now, go examine the site to see if you can figure out how their requests work. If they have a <form method="POST"> tag then look at all the <input> tags, including the hidden ones. If you can get that information, then its possible to recreate the request. (check your cookies too)

Update: I forgot to mention that before you do this you should check their terms of service. Often sites don't like this sort of thing. You may not agree with that, but that won't stop them from making your life unhappy if they catch you doing it.

Lobster Aliens Are attacking the world!

Replies are listed 'Best First'.
Re: Re: Converting Javascript to Perl
by sulfericacid (Deacon) on Apr 14, 2003 at 20:49 UTC
    I got the login form/redirect to work and it actually logs the user in and redirects to my script. As of right now I am not using anything but CGI (once I get this setup and if it doesn't work I'll add the other modules you suggestion). I have run into a problem though.

    his code

    <INPUT TYPE=checkbox NAME=delCheck1> <INPUT TYPE=hidden NAME=delCode1 VALUE=10001> 1
    I'm not using checkboxes, instead I am using a textfield using:
    textfield(-name=>delCheck1, -size=>3,
    My question is how can I setup the hidden field right after it and set the value to param(delCheck1)? I need the hidden field to have the numeric number of the note they placed inside my first textfield, any ideas on how to go about this?

    Thanks so much!

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid

      Here's what I would do: After they log-in I would grab the page with the checkboxes and hidden fields on it from the remote server. Parse it and get the checkboxes and number fields out (I'd use HTML::TokeParser for that) so they would have checkboxes like the would normally had they actually logged into the remote server.

      Theoretically if there are no cookies involved you could simply cause the form to post back to their server (though they would be taken there). If you want them to remain on your site you can use LWP to post the info yourself and send the user back to your own success page (or error page if the Post request to the remote server fails)

      All of that is the *best way* as it doesn't require your user to know the numbers. However if you don't want to go to all that trouble and you want the user to enter the numbers the simplest way to add the hidden field would be to use javascript (no one shoot me for putting some JS code here :)). Go ahead and create a hidden field with the correct name but leave its value blank and then do this: (untested!)

      <form method="POST" action="somescript.cgi" onSubmit="addHiddenFields( +this)">
      And then in your script section:
      function addHiddenFields(myform) { myform.delCode1.value = myform.delCheck1.value; }

      If you have more than one you can just add them or use arrays and loops to add them dynamically. JS is really quite simple.

      Lobster Aliens Are attacking the world!