BaoYaEr
利用htmlparser抓取網頁內容
import
org.htmlparser.Node;
import
org.htmlparser.NodeFilter;
import
org.htmlparser.Parser;
import
org.htmlparser.filters.TagNameFilter;
import
org.htmlparser.tags.TableTag;
import
org.htmlparser.util.NodeList;
public
class
TestYehoo
{
public
static
String testHtml()
{
String testText
=
""
;
try
{
String sCurrentLine;
String sTotalString;
sCurrentLine
=
""
;
sTotalString
=
""
;
java.io.InputStream l_urlStream;
java.net.URL l_url
=
new
java.net.URL(
"
http://sports.sina.com.cn/iframe/nba/live/
"
);
java.net.HttpURLConnection l_connection
=
(java.net.HttpURLConnection) l_url
.openConnection();
l_connection.connect();
l_urlStream
=
l_connection.getInputStream();
java.io.BufferedReader l_reader
=
new
java.io.BufferedReader(
new
java.io.InputStreamReader(l_urlStream));
while
((sCurrentLine
=
l_reader.readLine())
!=
null
)
{
sTotalString
+=
sCurrentLine;
}
System.out.println(sTotalString);
System.out.println(
"
====================
"
);
testText
=
extractText(sTotalString);
System.out.println(testText);
}
catch
(Exception e)
{
e.printStackTrace();
}
return
testText;
}
/** */
/**
* 抽取純文本信息
*
*
@param
inputHtml
*
@return
*/
public
static
String extractText(String inputHtml)
throws
Exception
{
StringBuffer text
=
new
StringBuffer();
Parser parser
=
Parser.createParser(
new
String(inputHtml.getBytes(),
"
UTF-8
"
) );
//
遍歷所有的節點
NodeList nodes
=
parser.extractAllNodesThatMatch(
new
NodeFilter()
{
public
boolean
accept(Node node)
{
return
true
;
}
}
);
Node node
=
nodes.elementAt(
0
);
text.append(
new
String(node.toPlainTextString().getBytes(
"
UTF-8
"
)));
return
text.toString();
}
/** */
/**
* 讀取文件的方式來分析內容. filePath也可以是一個Url.
*
*
@param
resource
* 文件/Url
*/
public
static
void
test5(String resource)
throws
Exception
{
Parser myParser
=
new
Parser(
"
http://sports.sina.com.cn/iframe/nba/live/
"
);
//
設置編碼
myParser.setEncoding(
"
GBK
"
);
String filterStr
=
"
table
"
;
NodeFilter filter
=
new
TagNameFilter(filterStr);
NodeList nodeList
=
myParser.extractAllNodesThatMatch(filter);
TableTag tabletag
=
(TableTag) nodeList.elementAt(
2
);
System.out.println( tabletag );
}
/**/
/*
* public static void main(String[] args) { TestYahoo testYahoo = new
* TestYahoo(); testYahoo.testHtml(); }
*/
public
static
void
main(String[] args)
throws
Exception
{
test5(
"
http://sports.sina.com.cn/iframe/nba/live/
"
);
}
}
結果:
TableTag
********
<
table
width
="750"
border
="0"
cellspacing
="0"
cellpadding
="0"
>
<
tr
>
<
td
bgcolor
="#990000"
height
="26"
style
="padding-left:10px;"
><
font
color
="#ffffff"
>
<
b
class
="f14"
><
a
href
="http://nba.sports.sina.com.cn/index.php"
class
="a01"
>
NBA數據庫
</
a
></
b
>
|
<
a
href
="http://nba.sports.sina.com.cn/live.php"
class
="a01"
>
比分直播
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/match_result.php"
class
="a01"
>
賽程賽果
</
a
>
|
<
a
class
="a01"
>
賽季總結
</
a
>
|
<
a
class
="a01"
>
交戰記錄
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/league_order.php"
class
="a01"
>
賽季排名
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/order.php"
class
="a01"
>
統計排行
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/arena.php"
class
="a01"
>
球員擂臺
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/team_order.php"
class
="a01"
>
近期戰績
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/teams.php"
class
="a01"
>
球隊
</
a
>
|
<
a
href
="http://nba.sports.sina.com.cn/players.php"
class
="a01"
>
球員
</
a
>
|
<
a
href
="http://sports.sina.com.cn/nba/"
class
="a01"
>
NBA專題
</
a
></
font
></
td
>
</
tr
>
</
table
>
發表于 2007-05-28 13:34
大田斗
閱讀(1899)
評論(0)
編輯
收藏
所屬分類:
開源opensource
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
mule事件驅動服務
XPath語法
mule示例分析
在xml的汪洋中遨游之mule篇
EqualsBuilder和HashCodeBuilder
webservice cfx學習
JTA事務初級研究
JAVA 對象池
mina中文教程
spring+atomikos+JTA完整例子
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
導航
BlogJava
首頁
發新隨筆
發新文章
聯系
聚合
管理
統計
隨筆: 32
文章: 427
評論: 144
引用: 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(5)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2008年12月 (1)
2008年4月 (2)
2008年2月 (1)
2008年1月 (1)
2007年12月 (3)
2007年11月 (1)
2007年10月 (3)
2007年7月 (2)
2007年6月 (1)
2007年4月 (2)
2007年3月 (3)
2007年2月 (5)
2007年1月 (3)
2006年12月 (4)
文章分類
axis(6)
(rss)
eclipse(7)
(rss)
Hibernate(30)
(rss)
html/js/css(107)
(rss)
java(106)
(rss)
linux(7)
(rss)
Lucene(7)
(rss)
spring(36)
(rss)
Spring CLOUd(1)
(rss)
Strtus(30)
(rss)
其它(48)
(rss)
開源opensource(48)
(rss)
數據庫DateBase(30)
(rss)
設計模式(12)
(rss)
文章檔案
2018年8月 (1)
2012年5月 (1)
2012年4月 (2)
2011年7月 (6)
2010年3月 (1)
2010年2月 (1)
2010年1月 (3)
2009年12月 (1)
2009年10月 (1)
2009年8月 (3)
2009年3月 (1)
2009年2月 (1)
2008年12月 (3)
2008年11月 (10)
2008年10月 (3)
2008年9月 (2)
2008年8月 (2)
2008年7月 (4)
2008年6月 (13)
2008年5月 (15)
2008年4月 (9)
2008年3月 (10)
2008年1月 (18)
2007年12月 (33)
2007年11月 (6)
2007年10月 (18)
2007年9月 (10)
2007年8月 (18)
2007年7月 (15)
2007年6月 (25)
2007年5月 (19)
2007年4月 (26)
2007年3月 (38)
2007年2月 (33)
2007年1月 (27)
2006年12月 (27)
2006年11月 (12)
java
Ajax特效網站
cndiy nio
GRO
Hani Suleiman's blog
Java之路
java論壇
J道
mule
mule 入門
oksonic(動畫教程)
一路由你
中國eclipse
八進制
在線源碼
多線程實戰
天火
小米的blogjava
幻境伯克----jface/swt
很全的博克-強
每日一得
滿江紅
邢紅瑞
飛翔
鳥詩選(js)
鳥食軒 (dhtml)
工具
apache中文手冊
extjs學習
iconFindre
java 安全
javaresearch
java技巧網
js之王
matrix(study)
prototype api
spring中文
北京IT企業速查
在線流程圖工具
雅虎翻譯
朋友
Happyshow
hibernate異常
skywalker
sunshow
xf
亞光
同云博客
小弟鵬
張玉磊
昕
李陽
黃鳴
搜索
積分與排名
積分 - 1101800
排名 - 28
最新評論
1.?re: hibernate.cfg.xml配置
好全啊 .. 棒棒噠 ~ !
--junqinag.yang
2.?re: Quartz任務調度快速入門
我現在來看還是覺得不錯
--小任
3.?re: js中this的總結
評論內容較長,點擊標題查看
--pam
4.?re: Quartz任務調度快速入門
樓主辛苦
--yd
5.?re: Quartz任務調度快速入門
頂了,內容寫的很好
--sen
閱讀排行榜
1.?網頁不緩存(3553)
2.?Form嵌套引起的問題 (2852)
3.?解決IE下CSS背景圖片閃爍的Bug(2447)
4.?Spring AOP的動態載入原理(2405)
5.?如何制作漂亮的Excel表格(2046)
評論排行榜
1.?北京戶口--吃官司(5)
2.?開始→運行→輸入的命令集錦(3)
3.?讓網頁上的所有圖片動起來(2)
4.?Dom4j 編碼問題徹底解決 (1)
5.?心情不爽(1)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 大田斗
主站蜘蛛池模板:
最新亚洲精品国偷自产在线
|
久久亚洲国产视频
|
亚洲狠狠色丁香婷婷综合
|
亚欧在线精品免费观看一区
|
亚洲综合在线观看视频
|
999任你躁在线精品免费不卡
|
亚洲国产日韩在线视频
|
久久久久久久99精品免费观看
|
亚洲成a人片在线观看日本
|
成人精品一区二区三区不卡免费看
|
国产亚洲情侣一区二区无码AV
|
亚洲综合精品香蕉久久网
|
eeuss影院ss奇兵免费com
|
国产精品亚洲一区二区三区在线
|
久久亚洲AV成人出白浆无码国产
|
午夜免费福利视频
|
亚洲三级视频在线
|
精品免费国产一区二区三区
|
免费国产在线精品一区
|
国产成人精品日本亚洲网站
|
99ee6热久久免费精品6
|
亚洲国产精品18久久久久久
|
99久久人妻精品免费二区
|
国产成人亚洲合集青青草原精品
|
中文字幕亚洲日本岛国片
|
国产精品99久久免费观看
|
亚洲Av无码一区二区二三区
|
免费一级毛片清高播放
|
一个人免费视频观看在线www
|
亚洲理论片在线中文字幕
|
免费观看男人免费桶女人视频
|
中文字幕成人免费高清在线
|
久久久久亚洲Av片无码v
|
国产成人午夜精品免费视频
|
菠萝菠萝蜜在线免费视频
|
久久精品国产亚洲香蕉
|
免费鲁丝片一级在线观看
|
久久国产精品国产自线拍免费
|
在线观看日本亚洲一区
|
亚洲精品无码专区久久久
|
野花高清在线观看免费3中文
|