【发布时间】:2013-12-20 01:31:37
【问题描述】:
我想打印 XPath 节点的内容。这是我所拥有的:
require "mechanize"
agent = Mechanize.new
agent.get("http://store.steampowered.com/promotion/snowglobefaq")
puts agent.xpath("//*[@id='item_52b3985a70d58']/div[4]")
这会返回:<main>: undefined method xpath for #<Mechanize:0x2fa18c0> (NoMethodError)。
我刚开始使用 Mechanize,不知道自己在做什么,但是,我使用了 Watir,并认为这会起作用,但它没有。
【问题讨论】:
-
你可以像这样使用它:
agent.page.at("//*[@id='item_52b3985a70d58']/div[4]")