如何创建 nokogiri 不区分大小写的文本 * 搜索?
目前,
words = []
words << "philip morris"
words << "Philip morris"
words << "philip Morris"
words << "Philip Morris"
for word in words
doc.search("[text()*='#{word}']")
end
当我使用 hpricot 时,我发现在 gem 中可以将结果小写,这样我就可以将所有搜索保持小写,但是 nokogiri 很难找到可以做到这一点的地方。有人知道有办法做到这一点吗? 非常感谢您抽出时间
Currnetly I am doing
words = []
words << "philip morris"
words << "Philip morris"
words << "philip Morris"
words << "Philip Morris"
for word in words
doc.search("[text()*='#{word}']")
end
When I was using hpricot I found where to downcase the results within the gem so I could just keep all my searchs lowercase, however nokogiri has been quite difficult to find where one could even do that. Is anyone aware of a way to do this?
Thank you very much for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
lower-case
XPath 函数不可用,但您可以使用translate
XPath 1.0 函数将文本转换为小写,例如英语字母表:我似乎无法将其与
*=
运算符结合使用,但您可以使用contains
来进行子字符串搜索,从而完成完整的操作:The
lower-case
XPath function is not available but you can use thetranslate
XPath 1.0 function to convert your text to lowercase e.g. for the English alphabet:I couldn't seem to use this in combination with the
*=
operator but you can usecontains
to do a substring search instead, making the full thing: