HTML 解析/提取器 woody

码农软件 · 软件分类 · HTML解析器 · 2019-04-02 20:58:16

软件介绍

woody 是一款 Java 的HTML 解析/提取器,用法非常类似 webmagic, 是对其抽取模块完全重写,之所有单独提取出来是因为为来更好可重用。

一些新功能:

  • 多种结果数据类型(String, char, byte, short int, long, double, float, string[], Set, List,Data)
  • 支持用户之定义脚本处理函数(目前支持Javascript 函数配置处理)
  • 支持css,xpath内核替换
  • 支持filter功能
  • 对css,xpath 内核对象的缓存

一个完整的例子:

public class OsChinaBlog {

	public static void main(String[] args) throws Exception {
		Document doc = Jsoup.connect("http://www.oschina.net/news/43879/webmagic-0-3-0").timeout(60000)
				.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0").get();
		String html = doc.html();
		OsChinaBlogModel model = AnnotationExtractor.me().process(html, OsChinaBlogModel.class);
		System.out.println(model.toJson());
	}

	public static class OsChinaBlogModel extends Model {

		public OsChinaBlogModel() {
			//use to reflect
		}

		@Inject
		@ComboExtract(value = { @ExtractBy(value = "h1.OSCTitle", type = ExprType.CSS),
				@ExtractBy(value = "//title/text()", type = ExprType.XPATH) }, op = OP.OR)
		public String title;

		@Inject
		@ExtractBy(value = "div.PubDate a[href~=http://my\\.oschina\\.net/]", type = ExprType.CSS)
		public String author;

		@Inject
		@ExtractBy(value = "发布于.\\s*(\\d+年\\d+月\\d+日)", type = ExprType.REGEX)
		public Date publishDate;

		@Inject
		@ComboExtract(value = {
				@ExtractBy(value = "div.PubDate", type = ExprType.CSS, setting = @Setting(outerHtml = true)),
				@ExtractBy(value = "(\\d+)评", type = ExprType.REGEX) }, op = OP.AND)
		public int commentNum;

		@Inject
		@ExtractBy(value = "span#p_favor_count", type = ExprType.CSS, setting = @Setting(function = @Function(value = "replace", args = {
				"+", "" })))
		public int collectNum;

		@Inject
		@ComboExtract(value = {
				@ExtractBy(value = "div[id=userComments]", type = ExprType.CSS, setting = @Setting(outerHtml = true)),
				@ExtractBy(value = "div.TextContent", type = ExprType.CSS) }, op = OP.AND, multi = true)
		public List commentContents;

		@Inject
		@ExtractBy(value = "div[id=toolbar_wrapper]", setting = @Setting(fliters = { "b", "span" }), type = ExprType.CSS, impl = Document.class)
		public String weibo;

	}
}

本文地址:https://codercto.com/soft/d/2727.html

第四次革命

第四次革命

[意]卢西亚诺•弗洛里迪(Luciano Floridi)著 / 王文革 / 浙江人民出版社 / 2016-5 / 64.90元

 随着线上线下大融合以及人工智能的极大发展,人类已经进入超历史时代。在这一时代中,人类终于迎来了继哥白尼革命、达尔文革命、神经科学革命之后自我认知的第四次革命——图灵革命,整个世界正化身为一个信息圈,每个人都生活在云端,人类已不再是信息圈毋庸置疑的主宰。毫无疑问,图灵革命引爆了人工智能重塑整个人类社会的序曲!  那么在人工智能时代,人类如何保证自己最钟爱的财富——“隐私”不被窃取?如何应......一起来看看 《第四次革命》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具