提取“隐藏” HTML与Jsoup [英] Extracting "hidden" HTML with Jsoup

查看:132
本文介绍了提取“隐藏” HTML与Jsoup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取未出现在源文档中但可以公开的HTML数据,例如,通过Google Chrome中的检查元素。



示例页面: http://assignment.uspto.gov/#/search?q=9000000&sort=patAssignorEarliestExDate%20desc%2C%20id%20desc&synonyms=false





<





$ b pre> < script async =asynctype =text / javascriptsrc =https://components.uspto.gov/js/ais/2-2-assignment-search。 JS>< /脚本>

有没有办法用Jsoup提取这个隐藏的html?

解决方案

数据似乎是用AJAX加载的。 JSoup不处理Javascript。



您需要的是一个无头浏览器API,它可以在不实际渲染任何内容的情况下处理Javascript。



HtmlUnit似乎是最知名的工具,尽管我自己从未使用它。如前所述,Selenium Webdriver也是一个选项。



我相信你将不得不加载URL,等待所有的AJAX进行处理,最终你会得到几乎您可以在Java中使用与Chrome相同的解析树来处理它!


I am trying to get at HTML data that does not appear in the source document but can be exposed, for example, by "inspect element" in Google Chrome.

Example page: http://assignment.uspto.gov/#/search?q=9000000&sort=patAssignorEarliestExDate%20desc%2C%20id%20desc&synonyms=false

There are a number of div elements containing assignment data for U.S. Patent No. 9,000,000 that appear below the line

<script async="async" type="text/javascript" src="https://components.uspto.gov/js/ais/2-2-assignment-search.js"></script>

Is there a way to extract this hidden html with Jsoup?

解决方案

The data seems to loaded with AJAX. JSoup does not process Javascript.

What you need is a "headless browser" API, that processes Javascript without actually rendering anything.

HtmlUnit seems to be the best known tool, although I've never used it myself. As suggested before, Selenium Webdriver is also an option.

I believe you will have to load the URL, wait for all the AJAX to process, and you will eventually get almost the same parse tree you get in Chrome in Java to do with it as you wish!

这篇关于提取“隐藏” HTML与Jsoup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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