【发布时间】:2017-06-24 16:30:32
【问题描述】:
我想在 mechanize ruby 中使用 setTimeout 来加载整页。
我已尝试关注。但没用
mech = Mechanize.new { |agent|
agent.open_timeout = 5
agent.read_timeout = 5
}
有什么想法吗?
【问题讨论】:
标签: ruby settimeout mechanize
我想在 mechanize ruby 中使用 setTimeout 来加载整页。
我已尝试关注。但没用
mech = Mechanize.new { |agent|
agent.open_timeout = 5
agent.read_timeout = 5
}
有什么想法吗?
【问题讨论】:
标签: ruby settimeout mechanize
显然还有一个 idle_timeout,但我不确定有什么区别或者它是否真的有效:
mech.methods.grep /timeout=/
#=> [:idle_timeout=, :open_timeout=, :read_timeout=]
【讨论】:
我猜您正在尝试使用 JavaScript 中的 setTimeout 方法,但不幸的是,Mechanize 不理解 JavaScript 并且无法真正使用它(有关更多信息,请参阅 this question)。您使用的方法与 JavaScript 中的 setTimeout 功能是分开的。使用Watir 或类似的东西你可能会成功:
# this assumes that `browser' is a `Watir::Browser' object
browser.execute_script("window.setTimeout(my_code, 2000)")
【讨论】: