Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XPATH Ruby Nokogiri和后面的子字符串_Xpath - Fatal编程技术网

XPATH Ruby Nokogiri和后面的子字符串

XPATH 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: ')")

我有一些像这样的节点的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: ')")
然后它回来了

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