ruby 能够抓取动态网页内容如javascript或者ajax更新的内容?

不管用 net::http get 或者用其他方法open url,总是只能得到网页源代码类似的内容,实际动态显示在浏览器上的数据却怎么也得不到,诸位有经验可以分享吗?

如抓取一个javascript函数返回值等

我做过一个抓数据的脚本, 代码如何, 是否对你有帮助?
[code="java"]
class ClassName
HOST = "www.xxx.com"
URL = '/xxxx/xxx.php'
TABLE_REGEXP = /

/m

def http
@http ||= Net::HTTP.start(HOST, 80)
end

def initialize
end

def response
return @response unless @response.nil?
Net::HTTP.start(HOST, 80) do |http|
@response = Iconv.iconv("UTF-8//IGNORE","GB2312//IGNORE", http.get(URL).body).to_s
end
end

def html_table
@html_table ||= response.match(TABLE_REGEXP).to_s
end
end

ClassName.html_table
[/code]

可应用一些模拟浏览器操作的插件或者GEM来获取
不过它一般也只能读HTML元素现在的数据

其实net::http get 也能获取的 不过你要想办法获取到当前浏览器的COOKIE 才行
以前就有想过研究,后来因为找到好的解决方案放弃了