XPATH Ruby Nokogiri和后面的子字符串
我有一些像这样的节点的HTMLXPATH Ruby Nokogiri和后面的子字符串,xpath,Xpath,我有一些像这样的节点的HTML <span>Website: http://example.com</span> 使用Ruby和Nokogiri提取此信息 doc.xpath("substring-after(//span[contains(.,'Website: ')],'Website: ')") 但是如果我使用 doc.at_xpath("substring-after(//span[contains(.,'Website: ')],'Website: ')")
<span>Website: http://example.com</span>
使用Ruby
和Nokogiri
提取此信息
doc.xpath("substring-after(//span[contains(.,'Website: ')],'Website: ')")
但是如果我使用
doc.at_xpath("substring-after(//span[contains(.,'Website: ')],'Website: ')")
然后它回来了
NoMethodError: undefined method `first' for "http://example.com":String
但是我不想使用doc.xpath
我想使用doc.at\u xpath
,因为我不想重写我的函数
我怎么能这么做?有什么建议吗?
多谢各位 请注意(//span[包含(,'Website:'),'Website:')之后的
子字符串包含一个bug。您应该一致地使用'Website:'
或'Website:'
。您是说contains(,'Website:')和'Website:'中的文本不同,那么它可能会产生错误?是的,很明显。如果字符串包含'Website:'
,那么它完全可能不包含'Website:'
,因此也不包含子字符串-after()
它。哦,我明白了。我更新我的问题。非常感谢。
NoMethodError: undefined method `first' for "http://example.com":String