无法使用框架集解析网页

时间:2016-08-21 04:58:06

标签: groovy jsoup

我试图解析Groovydoc,但是Jsoup并没有找到包含所有内容的框架集。

        Connection connection=Jsoup.connect('http://groovy-lang.org/api.html')
        Document document=connection.get()
        Elements element= document.getElementsByTag('frameset')
        element.each {println(it)}

1 个答案:

答案 0 :(得分:0)

如果您检查connection.get()返回的结果,则可以看到没有frameset标记:

println document

现在,如果您在浏览器中打开网站并使用开发工具查看它的HTML代码,您可以看到您要查找的frameset是{{1}的孩子来自源iframe

只需使用Jsoup加载http://docs.groovy-lang.org/latest/html/gapi网址即可获取iframe

frameset

或者,如果您不想对要解析的Connection connection = Jsoup.connect('http://docs.groovy-lang.org/latest/html/gapi') Document document = connection.get() Elements element = document.getElementsByTag('frameset') element.each { println it } 源网址进行硬编码,请查看this如何获取源网址的答案