[英]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. 唯一的唯一
name
是name
但似乎无法使用CSS选择器指定它。
From the module documentation : 从模块文档中 :
$mech->find_link(name => "something")
name_contains
and name_regex
are also available. name_contains
和name_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.