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


In reply to Help Getting WWW::Mechanize Link reference array to output to STD_OUT. by tfredett

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.