I need to use the perl LWP module to fetch the value of a hidden field in a html file. Basically, when i open the html file i am presented with a form, and the form has a hidden field called "userid". i need to use LWP to get the value of "userid" and store it in a userid.txt file
I would be really greatful if someone could tell me how to do this.
cheers
linda
2) parse the html file for the field named 'userid' with a regex, and slurp that into a string
3) parse out the relevant bit from the string fetched in step 2
4) open file.txt to write the append the new data to the text file
5) append data to text file
6) close file.txt
7) end program.
Um, does that help? That would be the logic I would use to write the script, and then just use LWP::simple perhaps, and the rest you can code in your own regular expressions instead of using another module like HTML::parse or some such.
Here's code that will fetch your page, and pull out the userid. I trust you'll know how to log it to a file once its in your hands:
use WWW::Mechanize; my $agent = WWW::Mechanize->new; $agent->get($uri); $agent->form_number(1); my $user_id = $agent->current_form->find_input('userid')->value; Please note that you'll need to set the $uri for this to work, plus you'll need to make sure that the right form is being selected. In the above example I assumed that the form you want is the first form, but it may be the 3rd on the page, in which case the $agent->form_number should be set to 3.