利用正则表达式提取网页中Table内的数据
来源:互联网 发布:图书馆借书数据流程图 编辑:程序博客网 时间:2024/04/29 02:12
利用正则表达式提取网页中Table内的数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pagedata = @"<table class=""tabContent"" style=""width:681px;"">
<tr><td width=""60"" id=""n001"">周六010</td>
<td width=""100"">英格兰甲级联赛</td>
<td id=""t036""><a href='http://info.sporttery.cn/football/history/information.php?match_id=7844' target='_blank'>诺维奇<strong> VS </strong>利兹联</a></td>
<td width=""100"">03-27 22:59</td>
<td width=""50""><input type=""checkbox"" id=""m036001"" name=""m036001"" value=""49465653"" onclick=""select_match('036001')""/>1.85</td><td width=""50""><input type=""checkbox"" id=""m036002"" name=""m036002"" value=""51465053"" onclick=""select_match('036002')""/>3.25</td><td width=""50""><input type=""checkbox"" id=""m036003"" name=""m036003"" value=""51465148"" onclick=""select_match('036003')""/>3.30</td> <td width=""50""><input type=""checkbox"" id=""all036"" onclick=""bao('036',3)""/></td></tr>
</tr> <tr><td width=""60"" id=""n037"">周六046</td>
<td width=""100"">苏格兰超级联赛</td>
<td id=""t037""><a href='http://info.sporttery.cn/football/history/information.php?match_id=7845' target='_blank'>阿伯丁<strong> VS </strong>圣米伦</a></td>
<td width=""100"">03-27 22:59</td>
<td width=""50""><input type=""checkbox"" id=""m037001"" name=""m037001"" value=""49465656"" onclick=""select_match('037001')""/>1.88</td><td width=""50""><input type=""checkbox"" id=""m037002"" name=""m037002"" value=""51464948"" onclick=""select_match('037002')""/>3.10</td><td width=""50""><input type=""checkbox"" id=""m037003"" name=""m037003"" value=""51465153"" onclick=""select_match('037003')""/>3.35</td> <td width=""50""><input type=""checkbox"" id=""all037"" onclick=""bao('037',3)""/></td></tr>
</tr> <tr><td width=""60"" id=""n038"">周六047</td>
<td width=""100"">苏格兰超级联赛</td>
<td id=""t038""><a href='http://info.sporttery.cn/football/history/information.php?match_id=7846' target='_blank'>凯尔特人(-1)<strong> VS </strong>基马诺克</a></td>
<td width=""100"">03-27 22:59</td>
<td width=""50""><input type=""checkbox"" id=""m038001"" name=""m038001"" value=""49465253"" onclick=""select_match('038001')""/>1.45</td><td width=""50""><input type=""checkbox"" id=""m038002"" name=""m038002"" value=""52464853"" onclick=""select_match('038002')""/>4.05</td><td width=""50""><input type=""checkbox"" id=""m038003"" name=""m038003"" value=""52465448"" onclick=""select_match('038003')""/>4.60</td> <td width=""50""><input type=""checkbox"" id=""all038"" onclick=""bao('038',3)""/></td></tr>
</tr>
</table>
";
string result="";
Regex re = new Regex(@"<tr><td.*?>(?<text1>.*?)</td>\s+?<td.*?>(?<text2>.*?)</td>\s+?<td.*?><a.*?>(?<text3>.*?)<strong> VS </strong>(?<text4>.*?)</a></td>\s+?<td.*?>(?<text5>.*?)</td>\s+?<td .*?><input .*?/>(?<text6>.*?)</td><td .*?><input .*?/>(?<text7>.*?)</td><td .*?><input .*?/>(?<text8>.*?)</td>"); ----*? 或+?表示非贪婪模式;\s+?决定了可以换行;使用RegexBuddy工具验证
int i = 0;
for (Match m = re.Match(pagedata); m.Success && i < 10; m = m.NextMatch())
{
result += m.Groups["text1"].Value.Trim() + "|";
result += m.Groups["text2"].Value.Trim() + "|";
result += m.Groups["text3"].Value.Trim() + "|";
result += m.Groups["text4"].Value.Trim() + "|";
result += m.Groups["text5"].Value.Trim() + "|";
result += m.Groups["text6"].Value.Trim() + "|";
result += m.Groups["text7"].Value.Trim() + "|";
result += m.Groups["text8"].Value.Trim() + "|";
result += "<br>";
i++;
}
Response.Write(result);
}
}
- 利用正则表达式提取网页中Table内的数据
- 提取html中table的正则表达式
- 利用正则表达式提取()内内容
- 提取网页中链接和标题的正则表达式
- 提取网页中链接和标题的正则表达式
- Java提取网页中url的正则表达式
- java利用正则表达式提取年月日数据
- java利用正则表达式提取年月日数据
- 【python学习笔记】用正则表达式从含中文的网页中提取数据(含编码转换)
- C#使用正则表达式提取网页中的信息数据
- 通过正则表达式提取网页
- 正则表达式提取数据的方法
- 正则表达式提取Json数据的方法
- php 正则抓取网页的table数据
- 利用正则表达式,提取天气预报。
- .net中 网页抓取数据(提取html中的数据,提取table中的数据)
- 提取网页的table时,遇到table中的两行(tr)中间有空行(或无空行)的正则表达式我的处理
- C#中利用正则表达式提取网文链接
- struts的基本配置
- windows端口占用问题
- android LinearLayout布局嵌套覆盖问题
- 匿名类实现WindowAdapter子类的实例化
- DSLR数码单反摄影原理与拍摄技法
- 利用正则表达式提取网页中Table内的数据
- Netstat状态分类
- Android 中添加 AT 命令流程
- 有12个小球,外形相同,其中一个小球的质量与其他11个不同
- jboss日志配置 .
- oracle创建新的数据库后如何连接到以前的数据库
- Android下的任务和Activity栈
- MVC初探 增删改查
- linux 安装gcc g++ gdb