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. 洛谷 1712 BZOJ 4653 [NOI2016]区间

    [题解] 先把区间按照未离散化的长度排序,保存区间长度,然后离散化区间端点.每次把区间覆盖的点的覆盖次数加1,如果某个点被覆盖次数大于等于m,就从前往后开始删除区间直到没有一个点被覆盖的次数大于等于m ...

  2. PAT 1131 Subway Map

    In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...

  3. 常量Constant

    常量通常指的是一个固定的值,例如:1.2.3.’a’.’b’.true.false.”helloWorld”等. 在Java语言中,主要是利用关键字final来定义一个常量. 常量一旦被初始化后不能再 ...

  4. [luoguP1196] 银河英雄传说(并查集)

    传送门 记录 up[x] 表示 x 上方有多少个 all[x] 表示当前连通的有多少个 find 的时候 和 合并的时候 更新一下即可 ——代码 #include <cstdio> #in ...

  5. KMP超强模板贴一份

    )== ) {         );         next[]=; ;         ;i<=n;i++) {             ]!=str[i]) j=next[j];      ...

  6. Weblogic补丁升级操作手冊

    1.查看Weblogic版本号 方法一 [weblogic@Weblogic201 ~]$ cd /home/weblogic/Oracle/Middleware/wlserver_10.3/serv ...

  7. TransModeler 交通仿真软件

    1.系统概述 TransModeler是美国Caliper公司开发的一个功能强大而操作灵活的交通仿真软件包,广泛适用于各类交通规划和交通仿真建模任务.TransModeler独特之处在于它提供了宏观/ ...

  8. willRotateToInterfaceOrientation 屏幕旋转

    /* 1.屏幕发生旋转后, 这个旋转事件会先传递给window的rootViewController(窗口的根控制器) 2.rootViewController又会将这个旋转事件传递给它的子控制器 * ...

  9. 删除windows服务 cygwin sshd

    $ cygrunsrv -R sshd     删除ssd服务

  10. LeetCode 811. Subdomain Visit Count (子域名访问计数)

    题目标签:HashMap 题目给了我们一组域名,让我们把每一个域名,包括它的子域名,计数. 遍历每一个域名,取得它的计数,然后把它的所有子域名和它自己,存入hashmap,域名作为key,计数作为va ...