link text retrieval

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using ..

$mech->find_all_links( ... )

in www::mechanize in order to find all links in a page.

Now how can I retrieve the link text in addition to url of the link??

suppose there is a link - click_here, with url -

Using $mech->find_all_links( ... ), I can find, but
how can I retrieve the text 'click_here' also??

Please help.  will deeply appreciate.

Thank you.

Re: link text retrieval

Quoted text here. Click to load it

How are you using it?

In list context?

In scalar context?

You should provide a short and complete program that we can run...

Quoted text here. Click to load it

Errr, by calling the strangley named "text()" method perhaps?

use warnings;
use strict;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
$mech->get(' ');

foreach my $link ($mech->find_all_links) {
    print $link->url, "\n";
    print "    ", $link->text, "\n";

Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg0cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.

Site Timeline