in reply to How do I return the text of a link after using find_link with WWW::Mechanize?

The links in WWW::Mechanize are WWW::Mechanize::Link objects. So you have to use their methods to get more than their auto-stringification.

use strict; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get('http://amazon.com/'); $mech->success or die $mech->status(); my $link_obj = $mech->find_link (text_regex => qr/computer/i ); printf( "%s\n\t%s\n\n", $link_obj->text(), $link_obj->url(), );

  • Comment on Re: How do I return the text of a link after using find_link with WWW::Mechanize?
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I return the text of a link after using find_link with WWW::Mechanize?
by SpacemanSpiff (Sexton) on Nov 09, 2005 at 22:35 UTC
    Thanks guys. I ended up with:
    my $topic_obj = $mech->find_link (text_regex => qr/[LINK TEXT]/i ); $PrevMsg = $topic_obj->url; $PrevMsg =~ s/[SORTED DATA]//g;
    and it works wonderfully.