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 ...
随机推荐
- 恶补数论(二) Baby-Step-Giant-Step 大步小步求离散模对数
知识概述 好吧,我承认这是我初三寒假就听过的知识,然而我现在早就高一了(又是寒假,只不过我已经在省选了...) 额,这是求离散模对数的一种算法 也就是求满足方程a^x≡b(mod p)的最小的x(其中 ...
- __repr__()
class A : def __init__(self,name): self.name=name #def __str__(self): # return '**%s**'%self.name de ...
- [luoguP3252] [JLOI2012]树(DP)
传送门 树上前缀和. 在树上找一条权值和为 s 的链,其中这个链上的点按深度递增(递减)(不同) dfs 每搜到一个点求它的前缀和 sum[x],放入 set 中. 在 set 中找 sum[x] - ...
- python之MD5、base64\base32解密
# -*- coding:utf-8 -*- import hashlib import base64 # 求最大公约数gys # def gys(m, n): # c = 1 # while(c ! ...
- 页面加载即执行JQuery的三种方法
[1]$(function( ){ }): $(function(){ $("#name").click(function(){ //adding your code here } ...
- 特种部队(codevs 1427)
题目描述 Description 某特种部队接到一个任务,需要潜入一个仓库.该部队士兵分为两路,第一路士兵已经在正面牵制住了敌人,第二路士兵正在悄悄地从后方秘密潜入敌人的仓库.当他们到达仓库时候,发现 ...
- 最小公倍数LCM
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 输入2个正整数A,B,求A与B的最小公倍数. Input 2个数A,B,中间用空格隔开.(1<= A,B <= ...
- VS2017 +NetCore2.2.0+WebApi项目整合SwaggerUI 以及遇到的坑
1.新建一个WebApi项目,这里不说了. 2.打开项目nuget管理控制台,在 https://www.nuget.org/ 搜索swagger的包:Swashbuckle.AspNetCore , ...
- jq 笔记
http://bbs.miaov.com/forum.php?mod=forumdisplay&fid=40 2014.10.10jquery 2.0 不兼容ie 6 7 8,以上更适合做移动 ...
- 使用CDN
CDN的全称是Content Delivery Network.中文直译过来是:内容交付网络. 它的主要意思是,将某些内容进行交付的网络.对于站点开发而言,我们所讲的内容通常指的是内容文件(比如jav ...