Forum Moderators: coopster & phranque

Message Too Old, No Replies

LWP Help

LWP Help

         

lindajames

8:05 pm on May 7, 2003 (gmt 0)

10+ Year Member



Hi,

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

jeremy goodrich

8:13 pm on May 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) fetch the html file with LwP

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.

lindajames

8:19 pm on May 7, 2003 (gmt 0)

10+ Year Member



oh, i was lookin for how this would be done in the code :)

any chance of telling me how i could do this in coding?

really appreciate your time

cheers
linda

jatar_k

9:29 pm on May 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe try this LWP::Simple [search.cpan.org]

dkubb

5:23 am on May 8, 2003 (gmt 0)

10+ Year Member



I use LWP quite frequently, but recently I've heard a buzz from experienced perl programmers about another library that uses LWP underneath called WWW::Mechanize. It was built to solve the type of problem you are proposing. I thought it'd be fun to learn it and help you with your problem; and found the module to be quite good.. I think I'll be using it more often.

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.

jatar_k

5:32 am on May 8, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hey dkubb, Welcome to WebmasterWorld from a fellow british columbian ;)

lindajames

8:08 am on May 8, 2003 (gmt 0)

10+ Year Member



thanx for that dkubb, will try it out now.

cheers
linda