zoukankan
html css js c++ java
正则表达式分析网页,获得中央一电视节目列表
String strUrl
=
"
http://www.cctv.com/tvguide/11/01/20061010/1.shtml
"
;
byte
[] pageHtml
=
HttpUtil.getPage(strUrl);
//
将页面转成string
String strHtml
=
new
String(pageHtml,
"
GB2312
"
);
String[][] ls
=
null
;
ls
=
StringUtil.splitByReg(strHtml,
"
(\\d{2}:\\d{2}:\\d{2})</font>.*<font >(.+)</font>.*</tr>\\r\\n<tr>
"
);
for
(
int
i
=
0
;i
<
ls.length;i
++
)
{
//
String[] ls1[] = StringUtil.splitByReg(ls[i],"");
System.out.print(ls[i][
0
]
+
"
##
"
+
ls[i][
1
]);
System.out.println();
}
/** */
/**
通用正则表达式解析函数
* splitByReg
*
@param
str 需要解析的字符串
*
@param
regExp 匹配的正则表达式
*
@return
解析后字符串数组
*/
public
static
String[][] splitByReg(String str,String regExp)
{
Pattern sp
=
Pattern.compile(regExp);
Matcher matcher
=
sp.matcher(str);
Vector
<
Vector
<
String
>>
colInoput
=
new
Vector
<
Vector
<
String
>>
();
while
(matcher.find())
{
Vector
<
String
>
v
=
new
Vector
<
String
>
();
for
(
int
i
=
1
;i
<=
matcher.groupCount();i
++
)
{
v.add(matcher.group(i));
}
colInoput.add(v);
}
String[][] resultList
=
null
;
if
(colInoput.size()
>
0
)
resultList
=
new
String[colInoput.size()][colInoput.get(
0
).size()];
for
(
int
i
=
0
;i
<
colInoput.size();i
++
)
{
String[] kk
=
new
String[colInoput.get(i).size()];
colInoput.get(i).copyInto(kk);
resultList[i]
=
kk;
}
return
resultList;
}
查看全文
相关阅读:
AJAX基础
DOM事件机制(事件捕获和事件冒泡和事件委托)
http协议
DOM实战-js todo
python常见面试题
jQuery快速入门
三级菜单
购物车
员工信息表
random模块
原文地址:https://www.cnblogs.com/polugen/p/532765.html
最新文章
2014 top100
redis之如何配置jedisPool参数
开源top100
安卓开发中非常炫的效果集合
nginx websocket
搭建自己的AppRTCDemo服务器
2015 年最热门的国人开发开源软件 TOP 50
九格宫
JavaScript
JavaScript 学习中
热门文章
JavaScript
JavaScript
JavaScript 学习中
给大家推荐 用 hBuilder编写代码非常好用
javascript 基础练习 做Bingo图
jquery
jQuery实现todo及轮播图
JavaScript中的坑
pure框架
了解ES6
Copyright © 2011-2022 走看看