Jump to content

Problem with virtual browsing

- - - - -

  • Please log in to reply
No replies to this topic

#1
tate

tate

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
Hi,

I am using LWP::UserAgent as a virtual browser to try and access some information from a site that I must do on a very regular basis. I have no problem fetching web sites and filling in forms so far. The problem i have is that the site has a search form where I can't find the forms name to fill in. On top of that it has a hidden button that pops up when you fill in the form that must be pressed before pressing the search button.

So my first question is: Is there a way to find a list of the forms on the site using LWP::UserAgent and or HTTP::Forms?
Edit: Figured this one out and also figured out I asked the wrong question, should have asked if there was a way to get a list of inputs. Example below for anyone else who happens across this.
sub printInputs{
    my ($response) = @_;
    my @forms = HTML::Form->parse($response);
    my $form = shift(@forms);
    my @inputs = $form->inputs;
    for(my $i=0; $i<$#inputs; $i++){
        my $input = $inputs[$i];
        my $type = $input->type;
        my $name = $input->name;
        my $value = $input->value;
        print "type='$type' name='$name' value='$value'\n";
    }
}
Second question is: Once filling the text box out connected to the hidden/pop-up button, do i use UserAgent->post twice to press the first button and then the search button?
Edit: Finally managed to solve this one. I just had to find the form->action and use it in a post as the url with the correct text in a box. Was a pain because of how the javascript needs to be emulated with perl code. Posting my code will not likely help anyone cause it will be different for each site with something like this because of the javascript.

Edited by tate, 02 April 2010 - 03:02 PM.
finally answered both of my questions.

twas brillig




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users