Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Problems with WWW:Mechanize and a form

by conor (Initiate)
on Jan 26, 2012 at 15:40 UTC ( #950134=perlquestion: print w/ replies, xml ) Need Help??
conor has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am trying to write a script that will navigate through a soccer website to the player of my choice and scrape their info for me. I have the scraping part working by just hard coding an individual player's page in, but trying to implement the navigation is giving me some problems. The website in question is www.soccerbase.com

I have to fill in a form present at the top of the page with the player's name, then submit it for the search. I have tried it two different ways(commenting out one of them) based on info i found online but to no avail. I am an absolute novice when it comes to Perl so any help would be greatly appreciated! Thanks in advance. here is my code:

#!/usr/bin/perl use strict; require WWW::Mechanize; require HTML::TokeParser; my $player = 'Luis Antonio Valencia'; #die "Must provide a player's name" unless $player ne 1; my $agent = WWW::Mechanize->new(); $agent->get('http://www.soccerbase.com/players/home.sd'); $agent->form_name('headSearch'); $agent->set_fields('searchTeamField', $player); $agent->click_button(name=>"Search"); #$agent->submit_form( # form_number => 1, # fields => { => 'Luis Antonio Valencia', } # ); my $stream = HTML::TokeParser->new(\$agent->{content}); my $player_name; $stream->get_tag("strong"); $player_name = $stream->get_trimmed_text("/strong"); print "\n", "Player Name: ", $player_name, "\n";

ps some things commented out are just still there from other stuff, they can be ignored

Comment on Problems with WWW:Mechanize and a form
Download Code
Re: Problems with WWW:Mechanize and a form
by Anonymous Monk on Jan 26, 2012 at 15:48 UTC

      thanks for the help, but i don't really understand what you linked me, as i said i am a complete Perl novice and it's taken me a while to even get to the stage i've posted above. Any help on my current code would be great.

        Web automation has ljittle to do with Perl itself. As the linked posts tell, it is all about finding what data a browser sends and then sending the equivalent data from Perl instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950134]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-08-01 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (258 votes), past polls