定义信息源的一些示例(xml文件)
这里有一些共享的信息源,点击Download按钮下载即可。
本文目录
1、订阅博客,简单一例
2、从网页获取信息,简单一例
3、充分使用callback回调代码
4、html_re中包含多个block
5、使用html_json这个worker,解析json数据
1、订阅博客,简单一例:
<source>
<name>范志红博客</name>
<comment>搜狐博客。原创营养信息。</comment>
<link>http://snowheart19.blog.sohu.com/</link> <worker>rss_atom</worker>
<data>
<url>http://snowheart19.blog.sohu.com/rss</url>
</data>
</source>
2、从网页获取信息,简单一例:
<source>
<name>ybk168新邮预告</name>
<comment>ybk168新邮预告</comment>
<link>http://www.ybk168.com/newslist/00040051.html</link> <worker>html_re</worker>
<data>
<url>http://www.ybk168.com/newslist/00040051.html</url>
<block>
<blockre flags='DOTALL'>
<![CDATA[
<div class="list">(.*?)<div class="page">
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
<li><span.*?href="([^"]+)".*?title="([^"]+)".*?
class="list_lr">([^<]+)<
]]>
</itemre>
<maprules>
<title>2</title>
<url>'http://www.ybk168.com', 1</url>
<pub_date>3</pub_date>
</maprules>
</block>
</data>
</source>
3、充分使用callback回调代码:
<source>
<name>北京空气质量</name>
<comment>北京环境监测的微博。',利有散染预【8时' in s or '浓度】' not in s</comment>
<link>http://weibo.cn/u/2516831703</link> <worker>html_re</worker>
<data>
<url>http://weibo.cn/u/2516831703</url> <block>
<blockre flags='DOTALL'>
<![CDATA[
<div class="b">(.*)$
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
weibo\.cn\[([\d-]+)
]]>
</itemre>
<maprules>
<title>'notitle'</title>
<pub_date>1</pub_date>
<suid>1</suid>
</maprules>
</block> <block>
<blockre flags='DOTALL'>
<![CDATA[
^(?:.*?\[<span class="kt">置顶</span>\]|.*?<span class="pms">)
(.*?)
<input type="submit" value="查看更多内容"
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
<div class="c" id="([^"]+)">
(?:<div><span class="ctt">|.*?<span class="cmt">转发理由:</span>)
(.*?)
(?:</span>|<a [^>]+>赞\[\d+\]).*?
<span class="ct">([^& ]+)
]]>
</itemre>
<maprules>
<title>'notitle'</title>
<summary>2</summary>
<pub_date>3</pub_date>
<suid>1</suid>
</maprules>
</block>
</data> <callback>
<![CDATA[
if posi == 0:
temp_date = info.pub_date
info.temp = 'del'
elif '日' in info.pub_date:
info.temp = 'del'
else:
s = info.summary
if ',' in s or \
'利' in s or \
'有' in s or \
'散' in s or \
'染' in s or \
'预' in s or \
'【8时' in s or \
'浓度】' not in s:
info.url = 'http://weibo.cn/u/2516831703'
info.pub_date = ''
info.title = '[' + temp_date + '] ' + s[:16] + '…'
else:
info.temp = 'del'
]]>
</callback>
</source>
4、html_re中包含多个block:
<source>
<name>中国国家地理</name>
<comment>中国国家地理</comment>
<link>http://www.dili360.com/</link> <worker>html_re</worker>
<data>
<url>http://www.dili360.com/</url> <block>
<blockre flags='DOTALL'>
<![CDATA[
<div class="community-item" id="community-items" >
(.*?)<!--end-->
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
<li class="img-block".*?
<a target="_blank" href="([^"]+)">.*?
<h4>(.*?)</h4>
]]>
</itemre>
<maprules>
<title>2</title>
<url>'http://www.dili360.com', 1</url>
</maprules>
</block> <block>
<blockre flags='DOTALL'>
<![CDATA[
<div class="community-item" id="community-items" >
(.*?)<!--end-->
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
<dt><a href="([^"]+)" target="_blank">(.*?)</a></dt>
]]>
</itemre>
<maprules>
<title>2</title>
<url>'http://www.dili360.com', 1</url>
</maprules>
</block> <block>
<blockre flags='DOTALL'>
<![CDATA[
<ul class="style-1" id="replace">(.*?)</ul>
]]>
</blockre>
<itemre flags='DOTALL'>
<![CDATA[
<div class="detail">.*?
<a href="([^"]+)" target="_blank"><h4>(.*?)</h4>
]]>
</itemre>
<maprules>
<title>2</title>
<url>'http://www.dili360.com', 1</url>
<summary>'景观图片'</summary>
</maprules>
</block> </data>
</source>
5、使用html_json这个worker,解析json数据:
<source>
<name>新浪书讯</name>
<comment>新浪图书,书讯。</comment>
<link>http://book.sina.com.cn/</link> <worker>html_json</worker>
<data>
<url>http://feed.mix.sina.com.cn/api/roll/get?callback=jsonp1436772833418&pageid=8&lid=156&num=20</url>
<re flags='DOTALL'>
<![CDATA[
^try\{\w+\(
(.*)
\);\}catch\(e\)\{\};$
]]>
</re> <block>
<block_path>'result', 'data'</block_path>
<title>'title'</title>
<url>'url'</url>
<summary>'summary'</summary>
<temp>'intro'</temp>
<pub_date>'ctime'</pub_date>
</block>
</data> <callback>
<![CDATA[
info.pub_date = unixtime(info.pub_date)
info.summary = info.summary or info.temp
info.temp = 0
]]>
</callback>
</source>
定义信息源的一些示例(xml文件)的更多相关文章
- 通过Bag一对多映射示例(使用xml文件)
如果持久化类具有包含实体引用的列表对象,则需要使用一对多关联来映射列表元素. 我们可以通过列表(list)或包(bag)来映射这个列表对象. 请注意,bag不是基于索引的,而list是基于索引的. 在 ...
- ACEXML解析XML文件——我是如何学习并在短时间内掌握一个库的使用方法的
最近做的C++项目中需要使用xml文件保存一些信息,程序启动时会读取这些信息.最终经过主程的评测,决定使用ACEXML库来读取解析XML文件. 好吧,至于为什么选择ACEXML库,我就不说了.既然选择 ...
- 集合映射Set(使用xml文件)
如果持久类具有Set对象,可以在映射文件中使用set元素映射Set集合. set元素不需要索引元素. List和Set之间的区别是: Set只存储唯一的值. 我们来看看我们如何在映射文件中实现集合: ...
- 集合映射中的映射包(使用xml文件)
如果持久类有List对象,我们可以通过列表或者bag元素在映射文件中映射. 这个包(bag)就像List一样,但它不需要索引元素. 在这里,我们使用论坛的场景: 论坛中一个问题有多个答案. 我们来看看 ...
- 集合映射中的映射列表(使用xml文件)
如果持久化类具有List对象,我们可以通过映射文件中的类的<list>元素或注释来映射List. 在这里,我们正在使用论坛的场景,其中一个问题有多个答案. 在这里,我们使用论坛的场景,其中 ...
- Java Web的web.xml文件作用及基本配置(转)
其实web.xml就是asp.net的web.config一个道理. 说明: 一个web中完全可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. web.xml文件是用来 ...
- web.xml 文件配置01
web.xml 文件配置01 前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...
- web.xml文件的作用
每个javaEE工程中都有web.xml文件,那么它的作用是什么呢?它是每个web.xml工程都必须的吗? 一个web中可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. ...
- [转] web.xml文件详解
转自:http://www.cnblogs.com/hellojava/archive/2012/12/28/2835730.html 前言:一般的web工程中都会用到web.xml,web.xml主 ...
随机推荐
- JAVA 内部类 泛型 实现堆栈
堆栈类: package c15; public class LinkedStack<T> { private static class Node<T> { T item ; ...
- html5/css学习笔记
请始终将正斜杠添加到子文件夹.假如这样书写链接:href="http://www.w3cschool.cc/html",就会向服务器产生两次 HTTP 请求.这是因为服务器会添加正 ...
- IOS线程学习(一)
1.NSThread 官方的描述 An NSThread object controls a thread of execution. Use this class when you want to ...
- Linux代码的重用与强行卸载Linux驱动
(一)Linux代码的重用 重用=静态重用(将要重用的代码放到其他的文件的头文件中声明)+动态重用(使用另外一个Linux驱动中的资源,例如函数.变量.宏等) 1.编译是由多个文件组成的Linux驱动 ...
- Node连接MySQL
http://blog.fens.me/nodejs-mysql-intro/ http://czpae86.iteye.com/blog/1636302 http://www.cnblogs.com ...
- BZOJ 1096 仓库建设
和上题类似吧.... #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- C语言格式化输入不定长数组
先随便写写,有空再整理. 直接贴代码 #include <stdio.h> #include <stdlib.h> //从一行标准输入中格式化输入一个不定长数组 void in ...
- oracle xmltype导入并解析Excel数据 (四)特别说明
1.Excel导出,此处没有给出 2.错误原因在中间表,T_EXCEL_IMPORT_GENERATION,其中errormsg不为空的数据 3,中间表入库过程: 需要自己实现,为一个存储过程,存储过 ...
- 模拟Post请求
此文摘自csdn青山的博客地址:http://blog.csdn.net/a497785609/article/details/6437154 本人随笔只为方便自己查阅,也为广大网友提供方便,不喜勿喷 ...
- Linux学习之路—Linux的历史发展
1.1969年以前:一个伟大的梦想-Bell,MIT与GE的"Multics"系统 由于早期的计算机不想现在这样普遍,所以往往出现这样的情况,主机只有一台而多人等待使用.好在20世 ...