我的BT下载实验室
姚明的NBA
BT下载
小说520
常用链接
我的随笔
我的文章
我的评论
我的参与
最新评论
留言簿
给我留言
查看公开留言
查看私人留言
随笔档案
(22)
2008年7月 (2)
2008年6月 (4)
2008年5月 (7)
2008年4月 (2)
2008年1月 (4)
2006年6月 (3)
文章档案
(1)
2008年1月 (1)
我最爱的网站
BT
NBA中文网
这个网站是我自己做的.呵呵.
NBA中文网
NBA中文网|NBA直播|NBA视频|NBA2008|科比|NBA火箭队|NBA湖人队|NBA球星|NBA赛程
小说520网
小说,小说520网
最新电影网
最新电影网,最新电影网,最新电影网
搜索
最新评论
1. re: 通过JOX轻松实现JavaBeans与XML的相互转换
xiaoran1392010@163.com
谢谢!
--llddy
2. re: 通过JOX轻松实现JavaBeans与XML的相互转换
jox官网下载不了了
能不能给我发一个 谢谢
hoohey@tom.com
--hoohey
3. re: 修正版 疯狂代码 写给WEB2.0的站长
你做了哪些网站?给大家看看?
--cn
4. re: 修正版 疯狂代码 写给WEB2.0的站长
评论内容较长,点击标题查看
--cool man
5. re: 修正版 疯狂代码 写给WEB2.0的站长
写得不错,支持一下@!
--bbmonkey62笨笨猴
阅读排行榜
1. Web cache 说明[翻译](2235)
2. 修正版 疯狂代码 写给WEB2.0的站长(2120)
3. 测试网站性能的30款免费在线工具(1766)
4. 如何分析网页-----使用HtmlParser(1)(1604)
5. 用freemarker生成静态页面(1516)
评论排行榜
1. 用freemarker生成静态页面(31)
2. 通过JOX轻松实现JavaBeans与XML的相互转换 (8)
3. 修正版 疯狂代码 写给WEB2.0的站长(7)
4. 解密淘宝网的开源架构(转)(6)
5. 如何分析网页-----使用HtmlParser(1)(6)
60天内阅读排行
1. Web cache 说明[翻译](2235)
2. 修正版 疯狂代码 写给WEB2.0的站长(2120)
3. 测试网站性能的30款免费在线工具(1766)
4. 用freemarker生成静态页面(1516)
5. 简单的运用Lucene进行检索(1378)
Powered by:
博客园
模板提供:
沪江博客
BlogJava
|
首页
|
发新随笔
|
发新文章
|
联系
|
聚合
|
管理
通过htmlParser抓取百度相关内容
最近这两天我做了个
最新电影网
的视频网站,主要是从土豆抓取来的.所以
内容页
就是框架,不便于搜索的抓取。所以我就想加些相关内容,像这样的
内容
由于我就是通过百度搜索关键字来填充内容。下面就是我通过htmlParser抓取的代码。
public
class
BaiduResultAction
extends
BaseAction
{
public
static
final
Logger logger
=
Logger
.getLogger(BaiduResultAction.
class
);
/** */
/**
* 组装新闻
*
*
@param
url
*
@return
*/
public
String compNews(String url)
{
String returnContent
=
null
;
try
{
ParserModel parserModel
=
new
ParserModel();
//
table 的抓取标签
String content
=
"
border=\
"
0
\
"
cellpadding=\
"
0
\
"
cellspacing=\
"
0
\
""
;
parserModel.setContent(content);
NodeClassNameFilter contentNodeClassNameFilter
=
new
NodeClassNameFilter(
TableTag.
class
, parserModel);
NodeList contentList
=
getAllNodeList(url,
contentNodeClassNameFilter);
//
对table的处理 只取第一个table中的一项记录
//
如果全部抓取内容,则要去掉最后一个break;
for
(
int
i
=
1
; i
<
contentList.size(); i
++
)
{
if
(contentList.elementAt(i)
instanceof
TableTag)
{
TableTag tableContent
=
(TableTag) contentList
.elementAt(i);
int
rowCount
=
tableContent.getRowCount();
TableRow[] arrRows
=
tableContent.getRows();
for
(
int
j
=
0
; j
<
arrRows.length; j
++
)
{
TableRow tableRow
=
arrRows[j];
TableColumn[] arrColumm
=
tableRow.getColumns();
for
(
int
k
=
0
; k
<
arrColumm.length; k
++
)
{
String columContent
=
arrColumm[k].toHtml();
if
(columContent
!=
null
)
{
String[] split
=
columContent.split(
"
<br>
"
);
if
(split.length
>
2
)
returnContent
=
split[
1
].substring(
0
,split[
1
].length()
-
4
);
}
break
;
}
}
}
break
;
}
}
catch
(IllegalArgumentException e)
{
//
TODO Auto-generated catch block
e.printStackTrace();
return
null
;
}
catch
(Exception e)
{
//
TODO Auto-generated catch block
e.printStackTrace();
}
return
returnContent;
}
public
static
void
main(String[] args)
throws
Exception
{
BaiduResultAction action
=
new
BaiduResultAction();
//
抓取sohu的内容.通过百度
String url
=
"
http://www.baidu.com/s?wd=%BA%DA%BF%CD%B5%DB%B9%FAII+11%28112%29++site%3Asohu.com
"
;
//
String url = "
http://bbs.hoopchina.com/htm_data/96/0712/274754.html
";
//
List<String> hrefList = sinaAction.parseLink(url, getIndexFilter());
/**/
/*
logger.debug(sinaAction.compNews(url));
*/
action.compNews(url);
}
}
效果如下:http://www.tondou.cn/c/2008-05-12/314146
发表于 2008-05-12 22:00
BT下载与小说520
阅读(1065)
评论(5)
编辑
收藏
评论
#
re: 通过htmlParser抓取百度相关内容
回复
更多评论
good....
#
re: 通过htmlParser抓取百度相关内容
回复
更多评论
有没有源码参考一下呀?ParserModel,NodeClassNameFilter这两个类都是自定义的吗?我用的类包是这里面的:htmlparser1_6_20060610
#
re: 通过htmlParser抓取百度相关内容
回复
更多评论
@晚秋
是自定义的.看你网名好像是女性哦.
#
re: 通过htmlParser抓取百度相关内容
回复
更多评论
呵呵,有没有源码呀?xiaoqiu369@hotmail.com.发一份可以吗?
#
re: 通过htmlParser抓取百度相关内容
回复
更多评论
我贴的就是原代码啊.
新闻频道
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子技术博客