需求:
需要采集js渲染的页面,有些网站的页面是js渲染的
实现:
基于HtmlUnit实现:
public static void getAjaxPage() throws Exception{
WebClient webClient = new WebClient();
webClient.setJavaScriptEnabled(true);
webClient.setCssEnabled(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setTimeout(Integer.MAX_VALUE);
webClient.setThrowExceptionOnScriptError(false);
HtmlPage rootPage = webClient.getPage("http://tt.mop.com/read_14304066_1_0.html");
System.out.println(rootPage.asXml());
}
maven依赖:
net.sourceforge.htmlunit htmlunit-core-js2.9 compilenet.sourceforge.htmlunit htmlunit2.9 compile
【Spider|HtmlUnit抓取js渲染页面】说明:
Nutch插件:nutch-htmlunit用于替换Nutch自身的Http Fetch组件
推荐阅读
- Java|Java基础——数组
- 人工智能|干货!人体姿态估计与运动预测
- java简介|Java是什么(Java能用来干什么?)
- Java|规范的打印日志
- Linux|109 个实用 shell 脚本
- 程序员|【高级Java架构师系统学习】毕业一年萌新的Java大厂面经,最新整理
- Spring注解驱动第十讲--@Autowired使用
- SqlServer|sql server的UPDLOCK、HOLDLOCK试验
- jvm|【JVM】JVM08(java内存模型解析[JMM])
- 技术|为参加2021年蓝桥杯Java软件开发大学B组细心整理常见基础知识、搜索和常用算法解析例题(持续更新...)