iteye_10043 2009-10-27 00:12
浏览 309
已采纳

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

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

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

  • 写回答

2条回答 默认 最新

  • Robin2Wu 2009-10-27 17:36
    关注

    我做过一个抓数据的脚本, 代码如何, 是否对你有帮助?
    [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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?