Java. How to use headless browsers for crawling web and scraping data from website.--转
https://www.linkedin.com/pulse/java-how-use-headless-browsers-crawling-web-scraping-data-taluyev/
Did you ever think to implement software to scrape data from web pages? I guess everyone could think about crawling web.
The simplest way to get data from remote page is run your preferable web browser, load target web page, select needed text, copy and past text into text editor for the following data transformations. Joke :)
To be honest how to automate this routine process? Let's determine primary tasks need to be solved for implementing our crawler.
- Load data from remote host. It is not a secret how to to this...
- Parse loaded html and build DOM (Document Object Model).
- Get data by traversing DOM or using CSS selectors.
- Save or pass data for other tasks.
Parsing static HTML is quite "easy task". There are Java libraries which do this task very well. I would recommend to take a look at http://jsoup.org It's enough in simple case.
How to be with hidden HTML which is created by Javascript? We need to use browser or implement browser :) Fortunately we do not have to implement our own browser if we want just to implement crawler. These browsers are already implemented. Our herous: http://phantomjs.org, https://slimerjs.org
How to organize communication between Java program and headless browser? On the stage appears "Ghost" driver. The both browsers support this driver out of the box. Ghost driver is "relative" of WebDriver. WebDriver is well known among test-engineers - a lot of code examples and manuals. We are free to use Maven for integration GHost driver into crawler application.
There are difference between http://phantomjs.org, https://slimerjs.org. It is well documented on FAQ page of Slimerjs project.
Makes sense to consider Javascript framework casperjs.org - is a navigation scripting & testing utility for PhantomJS and SlimerJS written in Javascript.
What if we do not want to use not PhantomJS nor SlimerJS? There are alternatives:
At this point I propose to make a pause. Now we have enough information to dive into implementing of web crawlers applications.
Analytics starts from data gulps :)
Please like and share if you find my arcticle usefull :-)
Java. How to use headless browsers for crawling web and scraping data from website.--转的更多相关文章
- 转:Red Hat JBoss团队发布WildFly 8,全面支持Java EE 7并包含全新的嵌入式Web服务器
原文来自于:http://www.infoq.com/cn/news/2014/02/wildfly8-launch Red Hat的JBoss部门今天宣布WildFly 8正式发布.其前身是JBos ...
- Java Spring Boot VS .NetCore (四)数据库操作 Spring Data JPA vs EFCore
Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...
- java.IO输入输出流:过滤流:buffer流和data流
java.io使用了适配器模式装饰模式等设计模式来解决字符流的套接和输入输出问题. 字节流只能一次处理一个字节,为了更方便的操作数据,便加入了套接流. 问题引入:缓冲流为什么比普通的文件字节流效率高? ...
- JAVA EE 第二周(XML简述以及web请求的过程)
一. 对于XML,我分别从以下几个方面来简述: 1.定义: XML是一种可扩展的标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. (可扩展标记语言:可扩展标记语言是一 ...
- Selenium(基于JAVA语言)-》在eclipse上运行web项目在Mac系统上启动时提示nodename nor servname provided解决办法
最近使用eclipse进行自动化测试时,遇到一种情况,无法调起浏览器,且有报错,如下: org.openqa.selenium.WebDriverException: failed to lookup ...
- [maven] "Dynamic Web Module 3.0 requires Java 1.6 or newer." OR "JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer."
在网上下载的开源工程,用maven构建的时候报错: Dynamic Web Module 3.0 requires Java 1.6 or newer. JAX-RS (REST Web Servic ...
- Java嵌入式数据库H2学习总结(三)——在Web应用中嵌入H2数据库
H2作为一个嵌入型的数据库,它最大的好处就是可以嵌入到我们的Web应用中,和我们的Web应用绑定在一起,成为我们Web应用的一部分.下面来演示一下如何将H2数据库嵌入到我们的Web应用中. 一.搭建测 ...
- Java嵌入式数据库H2学习总结(二)——在Web应用程序中使用H2数据库
一.搭建测试环境和项目 1.1.搭建JavaWeb测试项目 创建一个[H2DBTest]JavaWeb项目,找到H2数据库的jar文件,如下图所示: H2数据库就一个jar文件,这个Jar文件里面包含 ...
- JAVA 文件与base64之间的转化, 以及Web实现base64上传文件
<1>文件与base64字符串之间的转化 package servlet_file_upload; import java.io.File; import java.io.FileInpu ...
随机推荐
- PAT 1125 Chain the Ropes
Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...
- [模拟赛FJOI Easy Round #2][T3 skill] (最小割+最大权闭合子图(文理分科模型))
[题目描述] 天上红绯在游戏中扮演敏剑,对于高攻击低防御的职业来说,爆发力显得非常重要,为此,她准备学习n个技能,每个技能都有2个学习方向:物理攻击和魔法攻击.对于第i个技能,如果选择物理攻击方向,会 ...
- CodeForces 367E Sereja and Intervals
CodeForces 3 67E (109 + 7). Two ways are considered distinct if there is such j(1 ≤ j ≤ n), that the ...
- 纯JSP实现简单微信开发后台
%@ page import="java.net.*" % %@ page import="java.math.*" % %@ page import=&quo ...
- [51Nod1089] 最长回文子串 V2(Manacher算法)
1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 回文串是指aba.abba.cccbccc.aaaa这种左右对称 ...
- sql自增长和占位符?"相矛盾"的问题
1.对于sql server数据当数据被定义为自增长时,插入,无法将那个位置用字符占位,我们可以使用部分插入的方法来做. insert into users (username,email,grad ...
- ORACLE分区表删除分区数据
--全删除 ALTER TABLE tableName DROP PARTITION partionName UPDATE GLOBAL INDEXES; --清数据 ALTER TABLE tabl ...
- nyoj_127_星际之门(一)_201403282033
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门 ...
- Container/Injection 为什么会出现容器的思路,以后会有什么的趋势,未来是怎样的
一.为什么会出现容器的思路? 容器概念始于 1979 年提出的 UNIX chroot,它是一个 UNIX 操作系统的系统调用,将一个进程及其子进程的根目录改变到文件系统中的一个新位置,让这些进程只能 ...
- NYOJ 16 矩形嵌套 (DAG上的DP)
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 有n个矩形,每个矩形能够用a,b来描写叙述.表示长和宽.矩形X(a,b)能够嵌套在矩形Y(c,d)中当且仅当 ...