这里有一些共享的信息源,点击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&amp;pageid=8&amp;lid=156&amp;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文件)的更多相关文章

  1. 通过Bag一对多映射示例(使用xml文件)

    如果持久化类具有包含实体引用的列表对象,则需要使用一对多关联来映射列表元素. 我们可以通过列表(list)或包(bag)来映射这个列表对象. 请注意,bag不是基于索引的,而list是基于索引的. 在 ...

  2. ACEXML解析XML文件——我是如何学习并在短时间内掌握一个库的使用方法的

    最近做的C++项目中需要使用xml文件保存一些信息,程序启动时会读取这些信息.最终经过主程的评测,决定使用ACEXML库来读取解析XML文件. 好吧,至于为什么选择ACEXML库,我就不说了.既然选择 ...

  3. 集合映射Set(使用xml文件)

    如果持久类具有Set对象,可以在映射文件中使用set元素映射Set集合. set元素不需要索引元素. List和Set之间的区别是: Set只存储唯一的值. 我们来看看我们如何在映射文件中实现集合: ...

  4. 集合映射中的映射包(使用xml文件)

    如果持久类有List对象,我们可以通过列表或者bag元素在映射文件中映射. 这个包(bag)就像List一样,但它不需要索引元素. 在这里,我们使用论坛的场景: 论坛中一个问题有多个答案. 我们来看看 ...

  5. 集合映射中的映射列表(使用xml文件)

    如果持久化类具有List对象,我们可以通过映射文件中的类的<list>元素或注释来映射List. 在这里,我们正在使用论坛的场景,其中一个问题有多个答案. 在这里,我们使用论坛的场景,其中 ...

  6. Java Web的web.xml文件作用及基本配置(转)

    其实web.xml就是asp.net的web.config一个道理. 说明: 一个web中完全可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. web.xml文件是用来 ...

  7. web.xml 文件配置01

    web.xml 文件配置01   前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...

  8. web.xml文件的作用

    每个javaEE工程中都有web.xml文件,那么它的作用是什么呢?它是每个web.xml工程都必须的吗? 一个web中可以没有web.xml文件,也就是说,web.xml文件并不是web工程必须的. ...

  9. [转] web.xml文件详解

    转自:http://www.cnblogs.com/hellojava/archive/2012/12/28/2835730.html 前言:一般的web工程中都会用到web.xml,web.xml主 ...

随机推荐

  1. 学习Excel 十大函数

    云课堂视频教程 笔记总结: URL:http://study.163.com/course/courseLearn.htm?courseId=1009026#/learn/video?lessonId ...

  2. 堆糖瀑布流完整解决方案(jQuery)

    2010年堆糖创办以来,网站界面经历过3-5次重大改版,logo也曾更换过两次,早期蓝红相间三个圈的logo恐怕很少有人记得了.与此同时,前端 js 框架也在默默的更新换代.最早堆糖上线时,js 采用 ...

  3. NSString,NSArray,NSNumber等类的继承问题

    问题引入,我想给NSString类扩展一些新的方法.在Objective-C中可以有两种方法,一是继承,二是类别.本文先不讨论类别,我们用继承的方法试一下: @interface StringEx : ...

  4. 初探NIOS II之hello_world

    平台背景: 操作系统:win7  64bit 开发板:DE2-115 Quartus ii:15.0及配套的NIOS ii开发平台 一.硬件系统的建立 1.在Quartus里新建工程,这是很基本的就不 ...

  5. echo, print, print_r

    echo 不是函数,没有返回值,因此只是用作输出的话会更快 print 和 print_r 有返回值,区别在于: print 用于打印一个字符串,print_r 可以打印一些复合类型,如: $arr= ...

  6. Binary Tree Preorder Traversal -- LEETCODE 144

    方法一:(迭代) class Solution { public: vector<int> preorderTraversal(TreeNode* root) { vector<in ...

  7. javascript之小积累-匿名函数表达式的最佳实践

    在写js的时候,还是经常会用的匿名函数表达式,比如 setTimeout(function() { console.log(110); }, 1000); 上面那个function()就是匿名函数表达 ...

  8. PHP中CURL方法curl_setopt()函数的一些参数

    bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置,v ...

  9. 机器学习之分类器性能指标之ROC曲线、AUC值

    分类器性能指标之ROC曲线.AUC值 一 roc曲线 1.roc曲线:接收者操作特征(receiveroperating characteristic),roc曲线上每个点反映着对同一信号刺激的感受性 ...

  10. PHPnow在win8下安装失败的解决办法

    提示: 安装服务[ Apache_pn ]失败,可能原因如下:1.服务名已存在,请卸载或使用不同服务名.2.非管理员权限,不能操作Window NT服务. 解决方案: 搜索:命令提示符   , 右键以 ...