tread
tread

Reputation: 11098

How do you select specific HTML elements with no class or ID using WWW::Mechanize::Firefox?

I'm trying to loop through links on a page but i only want to loop through specific ones. The problem is that the links in <a> anchors do not have CSS ids or classes at all.

eg.

<a title="View More Information on FOO" href="tranlist.phtml?scode=FOO&sname=&refpg=1&snapcode=&ssector=1123&scheme=default" name="tranlist">

The only thing unique is the name but it doesn't seem like it can be specified with CSS selector.

Upvotes: 2

Views: 468

Answers (2)

Borodin
Borodin

Reputation: 126722

From the CSS specification, a CSS selector like a.normal is the same as a[class~=normal], and you can match any attribute that way. So you need

$mech->selector('a[name=tranlist]')

Upvotes: 2

Greg D&#39;Arcy
Greg D&#39;Arcy

Reputation: 968

From the module documentation:

$mech->find_link(name => "something")

name_contains and name_regex are also available.

[Edit: find_link_dom returns Firefox-specific MozRepl::RemoteObject::Instance objects, rather than standard WWW::Mechanize::Link objects which are returned by find_link. Amended for the more generic case.]

Upvotes: 2

Related Questions