简体   繁体   English

如何使用WWW :: Mechanize :: Firefox选择没有类或ID的特定HTML元素?

[英]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. 问题在于<a>锚点中的链接根本没有CSS ID或类。

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. 唯一的唯一namename但似乎无法使用CSS选择器指定它。

From the module documentation : 模块文档中

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

name_contains and name_regex are also available. name_containsname_regex也可用。

[Edit: find_link_dom returns Firefox-specific MozRepl::RemoteObject::Instance objects, rather than standard WWW::Mechanize::Link objects which are returned by find_link . [编辑: find_link_dom返回Firefox特定的MozRepl::RemoteObject::Instance对象,而不是由find_link返回的标准WWW::Mechanize::Link对象。 Amended for the more generic case.] 针对更一般的情况进行了修订。]

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. 根据CSS规范 ,像a.normal这样的CSS选择器与a[class~=normal] a.normal a[class~=normal] ,您可以通过这种方式匹配任何属性。 So you need 所以你需要

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM