简体   繁体   English

您可以使用带ruby nokogiri的通配符搜索html属性吗

[英]Can you search html attributes using wildcards with ruby nokogiri

I know you can search text in html using wildcards. 我知道您可以使用通配符在html中搜索文本。 Can you search for attribute values in html using wildcards with nokogiri 您可以使用带nokogiri的通配符在html中搜索属性值吗

eg, suppose I want to search for classes with value *session* 例如,假设我要搜索值为*session*

You can use xpath contains() function to search the document. 您可以使用xpath contains()函数搜索文档。 Something like: 就像是:

doc.xpath("//*[@*[contains(., 'session')]]").each do |ele|
  # something
end

This search returns all the elements with any attribute whose value contains the string 'session'. 此搜索返回具有任何属性的所有元素,这些属性的值包含字符串“ session”。

几天前发生了类似的问题-请注意类值周围的空格。

find(:xpath, "//*[contains(concat(' ', normalize-space(@class), ' '), ' icon-edit ')]")

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

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