tfredett has asked for the wisdom of the Perl Monks concerning the following question:
Oh great and wise monks, I am currently working on developing a script using the Perl Module WWW::Mechanize, I have gotten some of the things I need working, however I am running into an issue, and I am unsure how to resolve it. I have searched through the documentation as well as several good searches trying to figure out where I am going wrong to no avail. I am hoping that someone will see the mistake I am making.
I am using Mechanize to navigate to a webpage and run a search, that part works perfectly fine. However, when I finish my search, I want to go and retrieve a list of all the links on the new page, and be able to go through each link it finds to another page to retrieve information. Currently, to my knowledge, I am getting the list/array as I want, but I am unable to access it in the fashion I need. Instead, I normally get nothing printed to STD_OUT when taking in these links as an array, and I get a reference to an array printed to STD_OUT if I have it stored in a scalar. The problem I need is to be able to access this reference, but I am unable to figure out how to do that.
I have tried several things, but nothing has currently worked, I am currently just trying to get it to the point of printing the contents of the generated array to STD_OUT hence the foreach loop at the end of Search.
#!/usr/local/bin/perl require WWW::Mechanize; use strict; use warnings; { my $mech = WWW::Mechanize->new(); my $Input = ("LastName, FirstName"); &Search; sub Search { #print "Enter Search String:"; #goes to main search page. $mech->get('mywebsite.com/search.asp'); print "Webpage navigation start success result: "; &Get_Success; #submits the search form on the webpage just entered. $mech->submit_form ( form_number => 1, fields => {query => $Input, }); print "Form submission success result: "; &Get_Success; #finds all the links with "Server-" found inside the title. my @temp1 = $mech->find_all_links( text_regex => qr/Server-/i); print "Link retrieval success result: "; &Get_Success; foreach (@temp1) { print $_->url(), "\n"; print $_->text(), "\n"; print $_->name(), "\n"; print $_->tag(), "\n"; } sub Get_Success { #prints the success result and starts a new line. print $mech->success(); print"\n"; }
I have looked through these locations, and have found nothing I can see that helps me, perhaps I am just misunderstanding this information and how to use it. Any help is appreciated.
http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize.pm#LINK_METHODS
http://search.cpan.org/~jesse/WWW-Mechanize-1.72/lib/WWW/Mechanize/Link.pm#___top
http://forums.devshed.com/perl-programming-6/www-mechanize-link-array-reference-to-plain-english-276590.html
http://www.justskins.com/forums/mechanize-links-problem-49681.html
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help Getting WWW::Mechanize Link reference array to output to STD_OUT.
by zentara (Cardinal) on Jul 03, 2012 at 17:48 UTC | |
by tfredett (Sexton) on Jul 03, 2012 at 18:22 UTC | |
by Anonymous Monk on Jul 03, 2012 at 19:41 UTC | |
by tfredett (Sexton) on Jul 03, 2012 at 19:51 UTC | |
by Anonymous Monk on Jul 03, 2012 at 21:06 UTC | |
|