使用 `:contains` 后如何获取标签的兄弟标签?

How do I get the sibling of a tag after I use `:contains`?

我安装了 nokogiri gem 并制作了这个方法:

page = Nokogiri::HTML(open('http://example-page.com')
tag = 'div'
str = 'Some words in the div'
def tagContains(page, tag, str)
    return page.at(tag+':contains("'+str+'")').at('following-sibling::div')
end

但是它崩溃了。我想查找包含字符串的 div,然后是包含字符串 div 之后的 select div

您在第一行缺少 )

page = Nokogiri::HTML(open('http://www.99mac.se/'))
tag = 'div'
str = 'Some words in the div'
def tagContains(page, tag, str)
  page.at(tag+':contains("'+str+'") > div')
end

下次别忘了post你的错误信息。