jack123 has asked for the wisdom of the Perl Monks concerning the following question:

my $links = $mech1->find_all_links(class=>'listAnchor', url_regex=>/page=(\d+)$/); can someone answer me that how can i find links with certain class name ans also with certain url_regex please note that these are two different kinds of link on same page, one link is having special kind of class name for identification while other do have certain kind of url_regex in it take sample data as:
<div> <a class="listAnchor" href="/abc.com">abc</a> <a class="listAnchor" href="/def.com">def</a> <a class="listAnchor" href="/dedf.com">def</a> <a class="listAnchor" href="/desf.com">def</a> <a class="listAnchor" href="/deaf.com">def</a> </div> <ul> <li> <a>1</a> </li> <li> <a href="http://www.xyz/page=2">2</a> </li> <li> </ul>

Replies are listed 'Best First'.
Re: can we find two different kind of links using find_all_links
by Corion (Patriarch) on Apr 16, 2012 at 12:18 UTC

    Please (re)read the documentation to ->find_all_links. All the options you provide will construct an and condition, not an or condition. All links returned by ->find_all_links satisfy all conditions.

    You will also note that ->find_all_links can also return a list of found links. You can combine two lists by using the comma operator:

    my @links_with_class = $mech->find_all_links( class => ... ); my @links_with_regex = $mech->find_all_links( url_regex => ... ); my @links = @links_with_class, @links_with_regex;
Re: can we find two different kind of links using find_all_links
by tobyink (Canon) on Apr 16, 2012 at 13:23 UTC
    use List::MoreUtils qw/part/; my ($first_type, $second_type, $others) = part { if ($_->url =~ /page=(\d+)$/) { 0 } elsif ($_->attrs->{class} eq 'listAnchor') { 1 } else { 2 } } $mech1->find_all_links();
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: can we find two different kind of links using find_all_links
by Anonymous Monk on Apr 16, 2012 at 12:04 UTC

    :D What happens when you try?