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;
}
查看全文
相关阅读:
ubuntu 修改mysql 5.7数据库密码
maven 配置
数据仓库的命名规范
mysql 之 在查询字段中得出分钟数
mysql 之 timestampdiff() 函数 ,得到间隔分钟数
linux 服务器上下载文件到本地
mysql 之 时间格式 今年的第一天,去年的第一天
mysql 之 str_to_date ()函数 和date_format()函数
网络不可用时~更改DNS并刷新
mysql之 round()函数 , concat()函数
原文地址:https://www.cnblogs.com/polugen/p/532765.html
最新文章
b+树
MySQL和Oracle的区别
阿里天猫3面
分布式锁解决方案
BAT面试必问题系列:深入详解JVM 内存区域及内存溢出分析
mysql查看内存使用情况
用Java写一个递归遍历目录下面的所有文件
@RequestBody、@RequestParam、@PathVariable区别与使用场景
20 道 Spring Boot 面试题
使用spring的@Async异步执行方法
热门文章
4.9 多表单切换
4.8 定位一组元素
4.2 控制浏览器
2.4 编写第一个自动化脚本
4.1 selenium元素定位
一个爬虫从网页中爬取小说
编写一个简单的单元测试用例
JavaScript随堂笔记
自己试出来的 frame定位
存储过程
Copyright © 2011-2022 走看看