- 浏览: 1637935 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (405)
- C/C++ (16)
- Linux (60)
- Algorithm (41)
- ACM (8)
- Ruby (39)
- Ruby on Rails (6)
- FP (2)
- Java SE (39)
- Java EE (6)
- Spring (11)
- Hibernate (1)
- Struts (1)
- Ajax (5)
- php (2)
- Data/Web Mining (20)
- Search Engine (19)
- NLP (2)
- Machine Learning (23)
- R (0)
- Database (10)
- Data Structure (6)
- Design Pattern (16)
- Hadoop (2)
- Browser (0)
- Firefox plugin/XPCOM (8)
- Eclise development (5)
- Architecture (1)
- Server (1)
- Cache (6)
- Code Generation (3)
- Open Source Tool (5)
- Develope Tools (5)
- 读书笔记 (7)
- 备忘 (4)
- 情感 (4)
- Others (20)
- python (0)
最新评论
-
532870393:
请问下,这本书是基于Hadoop1还是Hadoop2?
Hadoop in Action简单笔记(一) -
dongbiying:
不懂呀。。
十大常用数据结构 -
bing_it:
...
使用Spring MVC HandlerExceptionResolver处理异常 -
一别梦心:
按照上面的执行,文件确实是更新了,但是还是找不到kernel, ...
virtualbox 4.08安装虚机Ubuntu11.04增强功能失败解决方法 -
dsjt:
楼主spring 什么版本,我的3.1 ,xml中配置 < ...
使用Spring MVC HandlerExceptionResolver处理异常
Jsoup是一个Java的HTML解析器,提供了非常方便的抽取和操作HTML文档方法,可以结合DOM,CSS和Jquery类似的方法来定位和得到节点的信息。
有着和Jquery一样强大的select和pipeline的API。
我们以从58同城网抽取租房信息为例,来说明如何使用它:
Selector overview
* tagname: find elements by tag, e.g. a
* ns|tag: find elements by tag in a namespace, e.g. fb|name finds <fb:name> elements
* #id: find elements by ID, e.g. #logo
* .class: find elements by class name, e.g. .masthead
* [attribute]: elements with attribute, e.g. [href]
* [^attr]: elements with an attribute name prefix, e.g. [^data-] finds elements with HTML5 dataset attributes
* [attr=value]: elements with attribute value, e.g. [width=500]
* [attr^=value], [attr$=value], [attr*=value]: elements with attributes that start with, end with, or contain the value, e.g. [href*=/path/]
* [attr~=regex]: elements with attribute values that match the regular expression; e.g. img[src~=(?i)\.(png|jpe?g)]
* *: all elements, e.g. *
Selector combinations
* el#id: elements with ID, e.g. div#logo
* el.class: elements with class, e.g. div.masthead
* el[attr]: elements with attribute, e.g. a[href]
* Any combination, e.g. a[href].highlight
* ancestor child: child elements that descend from ancestor, e.g. .body p finds p elements anywhere under a block with class "body"
* parent > child: child elements that descend directly from parent, e.g. div.content > p finds p elements; and body > * finds the direct children of the body tag
* siblingA + siblingB: finds sibling B element immediately preceded by sibling A, e.g. div.head + div
* siblingA ~ siblingX: finds sibling X element preceded by sibling A, e.g. h1 ~ p
* el, el, el: group multiple selectors, find unique elements that match any of the selectors; e.g. div.masthead, div.logo
Pseudo selectors
* :lt(n): find elements whose sibling index (i.e. its position in the DOM tree relative to its parent) is less than n; e.g. td:lt(3)
* :gt(n): find elements whose sibling index is greater than n; e.g. div p:gt(2)
* :eq(n): find elements whose sibling index is equal to n; e.g. form input:eq(1)
* :has(seletor): find elements that contain elements matching the selector; e.g. div:has(p)
* :not(selector): find elements that do not match the selector; e.g. div:not(.logo)
* :contains(text): find elements that contain the given text. The search is case-insensitive; e.g. p:contains(jsoup)
* :containsOwn(text): find elements that directly contain the given text
* :matches(regex): find elements whose text matches the specified regular expression; e.g. div:matches((?i)login)
* :matchesOwn(regex): find elements whose own text matches the specified regular expression
* Note that the above indexed pseudo-selectors are 0-based, that is, the first element is at index 0, the second at 1, etc
更多的信息可以参考[http://jsoup.org/|http://jsoup.org/]
有着和Jquery一样强大的select和pipeline的API。
我们以从58同城网抽取租房信息为例,来说明如何使用它:
package test import org.jsoup.nodes.Document import java.util.HashMap import org.jsoup.Jsoup /** * Author: fuliang * http://fuliang.iteye.com */ class HouseEntry(var title: String,var link: String,var price: Integer, var houseType: String, var date: String){ override def toString(): String = { return String.format("title: %s\tlink:%s\tprice:%d\thouseType:%s\tdate:%s\n", title,link,price,houseType,date); } } class HouseRentCrawler{ def crawl(url: String,keyword: String,lowRange: Int,highRange: Int): List[HouseEntry] = { var doc = fetch(url,keyword,lowRange,highRange); return extract(doc); } private def fetch(url:String,keyword: String,lowRange: Int,highRange: Int): Document = { var params = new HashMap[String,String](); params.put("final","1"); params.put("jump","2"); params.put("searchtype","3"); params.put("key",keyword); params.put("MinPrice",lowRange + "_" + highRange); return Jsoup.connect(url).data(params) .userAgent("Mozilla") .timeout(10000) .get(); } private def extract(doc: Document): List[HouseEntry] = { val elements = doc.select("#infolist > tr:not(.dev)"); var houseEntries = List[HouseEntry](); for(val i <- 0 until elements.size()){ val entry = elements.get(i); val fields = entry.select("td"); val title = fields.get(0).text(); val link = fields.get(0).select("a[class=t]").attr("href"); val price = fields.get(1).text().toInt; val houseType = fields.get(2).text(); val date = fields.get(3).text(); val houseEntry = new HouseEntry(title,link,price,houseType,date); houseEntries ::= houseEntry; } return houseEntries; } } object HouseRentCrawler{ def main(args: Array[String]) { val url = "http://bj.58.com/zufang"; val crawler = new HouseRentCrawler(); val houseEntries = crawler.crawl(url,"智学苑",2000,3500); for(val entry <- houseEntries){ println(entry); } } }
Selector overview
* tagname: find elements by tag, e.g. a
* ns|tag: find elements by tag in a namespace, e.g. fb|name finds <fb:name> elements
* #id: find elements by ID, e.g. #logo
* .class: find elements by class name, e.g. .masthead
* [attribute]: elements with attribute, e.g. [href]
* [^attr]: elements with an attribute name prefix, e.g. [^data-] finds elements with HTML5 dataset attributes
* [attr=value]: elements with attribute value, e.g. [width=500]
* [attr^=value], [attr$=value], [attr*=value]: elements with attributes that start with, end with, or contain the value, e.g. [href*=/path/]
* [attr~=regex]: elements with attribute values that match the regular expression; e.g. img[src~=(?i)\.(png|jpe?g)]
* *: all elements, e.g. *
Selector combinations
* el#id: elements with ID, e.g. div#logo
* el.class: elements with class, e.g. div.masthead
* el[attr]: elements with attribute, e.g. a[href]
* Any combination, e.g. a[href].highlight
* ancestor child: child elements that descend from ancestor, e.g. .body p finds p elements anywhere under a block with class "body"
* parent > child: child elements that descend directly from parent, e.g. div.content > p finds p elements; and body > * finds the direct children of the body tag
* siblingA + siblingB: finds sibling B element immediately preceded by sibling A, e.g. div.head + div
* siblingA ~ siblingX: finds sibling X element preceded by sibling A, e.g. h1 ~ p
* el, el, el: group multiple selectors, find unique elements that match any of the selectors; e.g. div.masthead, div.logo
Pseudo selectors
* :lt(n): find elements whose sibling index (i.e. its position in the DOM tree relative to its parent) is less than n; e.g. td:lt(3)
* :gt(n): find elements whose sibling index is greater than n; e.g. div p:gt(2)
* :eq(n): find elements whose sibling index is equal to n; e.g. form input:eq(1)
* :has(seletor): find elements that contain elements matching the selector; e.g. div:has(p)
* :not(selector): find elements that do not match the selector; e.g. div:not(.logo)
* :contains(text): find elements that contain the given text. The search is case-insensitive; e.g. p:contains(jsoup)
* :containsOwn(text): find elements that directly contain the given text
* :matches(regex): find elements whose text matches the specified regular expression; e.g. div:matches((?i)login)
* :matchesOwn(regex): find elements whose own text matches the specified regular expression
* Note that the above indexed pseudo-selectors are 0-based, that is, the first element is at index 0, the second at 1, etc
更多的信息可以参考[http://jsoup.org/|http://jsoup.org/]
发表评论
-
Lucene 索引格式
2013-06-25 20:11 0索引结构: 索引层次 ... -
计算广告学
2012-08-12 13:53 0计算广告学一: 1、核 ... -
《Lucene in Action》简单笔记
2011-12-22 09:19 0第一章 Meet Lucene -
Information Retrieval Resources
2011-04-07 16:40 1371Information Retrieval Resource ... -
常见文件类型识别
2010-09-22 20:09 11793根据文件的后缀名识别文件类型并不准确,可以使用文件的头信息进行 ... -
(zz)信息检索领域资料整理
2010-06-05 13:05 3137A Guide to Information Retrieva ... -
Introduce to Inforamtion Retrieval读书笔记(2)
2009-10-31 13:02 1894The term vocabulary and posting ... -
Introduce to Inforamtion Retrieval读书笔记(1)
2009-10-25 23:49 2013很好的一本书,介绍的非常全面,看了很久了,还没有看完,刚看完前 ... -
Query Log Mining notes
2009-10-02 18:08 1247Enhancing Efficiency of Search ... -
百度搜索的一些高级语法
2009-08-27 20:06 18961.title语法 就是在title ... -
Hadoop好书推荐:Hadoop The Definitive Guide
2009-08-16 22:49 3617第一本详细介绍Hadoop的书籍,从网上下来看了几章,作者是H ... -
Java开源搜索引擎[收藏]
2008-04-24 00:09 2881Egothor Egothor是一个用Java编写的开 ... -
分享一本斯坦福的信息检索的教材
2008-01-04 23:59 2434斯坦福的信息检索的教材,还没出版,先分享一下电子版原稿. 对于 ... -
分享一本搜索引擎的电子书
2007-12-29 19:42 2498还没有来得及看,但搜索引擎的书不是很好找,先放上,希望对大家能 ... -
分享一个Nutch入门学习的资料
2007-12-18 20:49 4245分享一个Nutch入门学习的资料,感觉写的还不错. -
搜索引擎Nutch源代码研究之一 网页抓取(4)
2007-12-17 22:37 8357今天来看看Nutch如何Parse网页的: Nutch使用了两 ... -
[转]MAP/REDUCE:Google和Nutch实现异同及其他
2007-12-15 19:21 2954设计要素 nutch包含以下几个部分: 辅助类 Log:记载运 ... -
Nutch源代码学习小小总结一下
2007-12-15 19:13 4426我现在看得源码主要是网页抓取部分,这部分相对比较容易。我首先定 ... -
搜索引擎Nutch源代码研究之一 网页抓取(3)
2007-12-15 16:39 4547今天我们看看Nutch网页抓取,所用的几种数据结构: 主要涉及 ... -
搜索引擎Nutch源代码研究之一 网页抓取(2)
2007-12-15 00:36 5529今天我们来看看Nutch的源代码中的protocol-h ...
相关推荐
使用Jsoup抽取数据.doc
jsoup 中文帮助文档 1. 解析和遍历一个html文档输入 2. 解析一个html字符串 3. 解析一个body片断 4. 根据一个url加载Document对象 5. 根据一个文件加载Document对象数据抽取 6. 使用dom方法来遍历一个Document对象 7...
jsoup Cookbook(中文版) 入门 解析和遍历一个html文档 输入 解析一个html字符串 解析一个body片断 根据一个url加载Document对象 根据一个文件加载Document对象 数据抽取 使用dom方法来遍历一个Document对象 使用选择...
jsoup中文帮助文档 doc 版本 目录 入门 1. 解析和遍历一个html文档 输入 2. 解析一个html字符串 3. 解析一个body片断 4. 根据一个url加载Document对象 5. 根据一个文件加载Document对象 数据抽取 6. 使用dom方法来...
jsoup Cookbook(中文版) 入门 1. 解析和遍历一个html文档 输入 2. 解析一个html字符串 3. 解析一个body片断 4. 根据一个url加载Document对象 5. 根据一个文件加载Document对象 数据抽取 6. 使用dom方法来遍历一个...
作为爬虫框架,它使用httpclient作为获取网页工具、使用Jsoup作为分析页面定位抓取内容、使用ExecutorService线程池作为定时增量抓取、Jdiy作为持久层框架。不熟悉这些名词的同学们可以先行百度一下这些都是什么,起...
WebMagic:一个开源的爬虫框架,提供了一些高级特性,如自动化抽取和数据抽取。 5.crawler4j:一个开源的爬虫框架,提供了一些基本功能,如多线程处理和网页解析。 FlyingSpider:一个开源的爬虫框架,专注于抓取...
使用非极大值抑制法确定镜头边界系数极大值并排序,以实现基于镜头边界系数的关键帧提取 JMF(Java视频处理): 功能 a)在Java Applet和应用程序中播放贵重物品媒体文件,如AVI、MPEG、WAV等; b)可以播放从互联网...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
jsoup是一个Java HTML Parser。能够从URL、文件或字符串解析HTML。利用DOM traversal或CSS selectors查找和抽取数据。能够操作HTML元素,属性和文本。能够依据一个白名单过滤用户提交的内容。
在数据的爬取上选用网上的现有API可以方便的进行数据分页的爬取,我们选用Jsoup进行数据的爬取。获取的数据源是东方财富网。在数据的选取上,考虑到短文本的限制,我们只爬取标题,选取对应的标签,爬取大概80000条...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...
源码中集成了Jsoup,可进行精准的网页解析。2.x版本中集成了selenium,可以处理JavaScript生成的数据。WebCollector特性:1、自定义遍历策略,可完成更为复杂的遍历业务,例如分页、AJAX2、可以为每个 URL 设置附加...
标签:根据帖子内容智能抽取关键字进行标签自动补全,一篇帖子关联多个标签。标签和标签之间以带边权重的图结构进行描述,方便进行相关计算 领域:一个领域下包含了多个标签,通过标签将帖子自动聚合到具体领域,...
Jsoup 入门 食用方法 fork 本项目,git clone 到本地,用 IDEA 导入。 继承抽象类 Parser,重写它的 generateCourseList 方法。 Common 中抽取了一些可能通用的解析函数,当然你也可以补充。 重写好函数后,新建一个...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...
Flume 是一个分布式、可靠和高可用的服务,用于收集、聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型。这是一个可靠、容错的服务。 彩信发送开发包 apimms apimms 提供了各种语言用来发送彩信...