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.

  1. Load data from remote host. It is not a secret how to to this...
  2. Parse loaded html and build DOM (Document Object Model).
  3. Get data by traversing DOM or using CSS selectors.
  4. 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.orghttps://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 WebDriverWebDriver 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.orghttps://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.--转的更多相关文章

  1. 转: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 ...

  2. Java Spring Boot VS .NetCore (四)数据库操作 Spring Data JPA vs EFCore

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  3. java.IO输入输出流:过滤流:buffer流和data流

    java.io使用了适配器模式装饰模式等设计模式来解决字符流的套接和输入输出问题. 字节流只能一次处理一个字节,为了更方便的操作数据,便加入了套接流. 问题引入:缓冲流为什么比普通的文件字节流效率高? ...

  4. JAVA EE 第二周(XML简述以及web请求的过程)

    一. 对于XML,我分别从以下几个方面来简述: 1.定义: XML是一种可扩展的标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. (可扩展标记语言:可扩展标记语言是一 ...

  5. Selenium(基于JAVA语言)-》在eclipse上运行web项目在Mac系统上启动时提示nodename nor servname provided解决办法

    最近使用eclipse进行自动化测试时,遇到一种情况,无法调起浏览器,且有报错,如下: org.openqa.selenium.WebDriverException: failed to lookup ...

  6. [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 ...

  7. Java嵌入式数据库H2学习总结(三)——在Web应用中嵌入H2数据库

    H2作为一个嵌入型的数据库,它最大的好处就是可以嵌入到我们的Web应用中,和我们的Web应用绑定在一起,成为我们Web应用的一部分.下面来演示一下如何将H2数据库嵌入到我们的Web应用中. 一.搭建测 ...

  8. Java嵌入式数据库H2学习总结(二)——在Web应用程序中使用H2数据库

    一.搭建测试环境和项目 1.1.搭建JavaWeb测试项目 创建一个[H2DBTest]JavaWeb项目,找到H2数据库的jar文件,如下图所示: H2数据库就一个jar文件,这个Jar文件里面包含 ...

  9. JAVA 文件与base64之间的转化, 以及Web实现base64上传文件

    <1>文件与base64字符串之间的转化 package servlet_file_upload; import java.io.File; import java.io.FileInpu ...

随机推荐

  1. 洛谷 2633 BZOJ 2588 Spoj 10628. Count on a tree

    [题解] 蜜汁强制在线... 每个点开一个从它到根的可持久化权值线段树.查询的时候利用差分的思想在树上左右横跳就好了. #include<cstdio> #include<algor ...

  2. [bzoj4300][绝世好题] (动规)

    Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). Input 输入文件共2行. 第一行包括一个整数 ...

  3. 关于Scrum 实战故事录播的感悟升级

    昨晚与几位自组织的伙伴进行了<Scrum 实战> 第17 章 <富有成效的每日站会>录播Sprint 不断的优化和精进的感悟. 首先,D兄给予了如下的建议: 1. 将段落 分得 ...

  4. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores

    #1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...

  5. [luoguP2285] [HNOI2004]打鼹鼠(DP)

    传送门 设f[i]表示i个鼹鼠出现后,打死鼹鼠的最大值 动态转移方程:f[i]=max{f[j]+1}, 条件:abs(x[i]-x[j])+abs(y[i]-y[j])<=time[i]-ti ...

  6. Win32编程API 基础篇 -- 5.使用资源

    使用资源 你可能想参考教程结尾的附近,为了获得跟VC++和BC++资源相关的信息. 在我们讲得更加深入之前,我将大致讲解一下资源的主题,这样在每个小节中我就不必再去重讲一遍了.在这一小节中,你不需要编 ...

  7. MapR CEO对2016大数据的5个预測

    本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2016/02/mapr-ceo-5-big-data-predictions MapR ...

  8. 分布式消息服务DMS如何实现死信消息的消费

    本文部分内容节选自华为云帮助中心的分布式消息服务(DMS)服务的产品介绍 死信消息是什么 死信消息是指无法被正常消费的消息.分布式消息服务DMS支持对消息进行异常处理.当消息进行多次重复消费仍然失败后 ...

  9. android:怎样在TextView实现图文混排

    我们通常在TextView文本中设置文字.但是怎样设置图文混排呢? 我就在这里写一个样例 .我们须要用到一点简单的HTML知识 在TextView中预订了一些类似HTML的标签,通过标签能够使Text ...

  10. 推荐微软Windows 8 Metro应用开发虚拟实验室

    Kevin Fan分享开发经验,记录开发点滴 推荐微软Windows 8 Metro应用开发虚拟实验室 2012-07-19 05:23 by jv9, 1940 阅读, 4 评论, 收藏, 编辑 微 ...