用于读取javascript生成内容的java html解析器 [英] java html parser for reading javascript generated contents

查看:338
本文介绍了用于读取javascript生成内容的java html解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jsoup 通过以下函数读取网页。

I am using jsoup for reading a web page by the following function.

public Document getDocuement(String url){
        Document doc = null;
        try {
            doc = Jsoup.connect(url).timeout(20*1000).userAgent("Mozilla").get();
        } catch (Exception e) {
            return null;
        }
        return doc;
    }

但每当我试图阅读包含<$ c $的网页时c> javascript 生成的内容, jsoup 不读取这些内容。即,页面的实际内容是通过一些 javascript 调用加载的。因此它不存在于该链接的页面源中。例如,此博客: http://blog.rapporter.net/search/label/r。在使用 Jsoup 解析页面时,有没有办法获得javascript生成的内容?如果没有请建议任何可以解决这个问题的java html解析器..

But whenever i am trying to read a web page that contain javascript generated contents, jsoup does not read those contents. ie, the actual content of the page is loading by some javascript calls.So it is not present in the page source of that link. For example, this blog: http://blog.rapporter.net/search/label/r. Is there a way to get also javascript generated content when parsing page with Jsoup? If no please suggest any java html parser that can solve this problem..

推荐答案

你不能用Jsoup 即可。 Jsoup解析HTML,等待AJAX​​请求或JavaScript内容一般你需要一个可以执行这个JavaScript的浏览器,以便从中获取一些输出。 JavaScript逻辑可能很复杂,因此执行JavaScript和加载内容并不是一件容易的事情(只需看看复杂的浏览器,JS和DOM是多少)。

You cannot do this with Jsoup. Jsoup parses HTML, to wait for AJAX requests or JavaScript content in general you would need a browser which could execute this JavaScript in order to get some output from it. JavaScript logic can be complex, so executing JavaScript and loading content is not a trivial thing (just take a look at how complicated browsers, JS and the DOM are).

这篇关于用于读取javascript生成内容的java html解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆