你可以用ruby nokogiri使用通配符来搜索html属性 [英] Can you search html attributes using wildcards with ruby nokogiri
本文介绍了你可以用ruby nokogiri使用通配符来搜索html属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道你可以使用通配符在html中搜索文本。你可以使用通配符在nokogiri中搜索html中的属性值,例如,假设我想搜索值为 * session * $的类您可以使用xpath contains()函数来搜索文档。您可以使用xpath contains()函数来搜索文档。例如:
doc.xpath(// * [@ * [contains(。,'session')]] )。每个do | ele |
#something
end
此搜索返回所有具有值包含字符串'session'。
I know you can search text in html using wildcards. Can you search for attribute values in html using wildcards with nokogiri
e.g., suppose I want to search for classes with value *session*
解决方案
You can use xpath contains() function to search the document. 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'.
这篇关于你可以用ruby nokogiri使用通配符来搜索html属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文