跪求asp.net/c# 正则表达式 截取HTML!
<trclass='a1'><tdwidth='84'rowspan='1'bgcolor='#EFF6FB'><divalign='center'>13层</div><...
<tr class='a1'> <td width='84' rowspan='1' bgcolor='#EFF6FB'><div align='center'>13层</div></td> <td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13A</div> <div align='center'><a href='housedetail.aspx?id=925352' target=_blank><img src='imc/b2.gif' border='0'></a></div></td> <td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13B</div> <div align='center'><a href='housedetail.aspx?id=925353' target=_blank><img src='imc/b1_2.gif' border='0'></a></div></td> <td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13C</div> <div align='center'><a href='housedetail.aspx?id=925354' target=_blank><img src='imc/b1_2.gif' border='0'></a></div></td> <td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13D</div> <div align='center'><a href='housedetail.aspx?id=925355' target=_blank><img src='imc/b3.gif' border='0'></a></div></td> <td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13E</div> <div align='center'><a href='housedetail.aspx?id=925356' target=_blank><img src='imc/b1_2.gif' border='0'></a></div></td> </tr>
<tr class='a1'>......</tr>
<tr class='a1'>......</tr>
......许多层许多房间
我要截取出来的字段: 层数、房号、房号详细页连接地址:如housedetail.aspx?id=925355、房间状态:如imc/b3.gif或者imc/b1_2.gif等
在线等ing.... 展开
<tr class='a1'>......</tr>
<tr class='a1'>......</tr>
......许多层许多房间
我要截取出来的字段: 层数、房号、房号详细页连接地址:如housedetail.aspx?id=925355、房间状态:如imc/b3.gif或者imc/b1_2.gif等
在线等ing.... 展开
展开全部
private void getRoom()
{
string strHtml = "<tr class='a1'>"
+ "<td width='84' rowspan='1' bgcolor='#EFF6FB'><div align='center'>13层</div></td> "
+ "<td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13A</div> <div align='center'><a href='housedetail.aspx?id=925352' target=_blank><img src='imc/b2.gif' border='0'></a></div></td>"
+ "<td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13B</div> <div align='center'><a href='housedetail.aspx?id=925353' target=_blank><img src='imc/b1_2.gif' border='0'></a></div></td></tr>";
string strKey = @"<tr class='a1'>[\s]*<td[.\s][^>]+><div align='center'>([\d]+层)</div></td>([\w\W]+)</tr>";
string strSubKey = @"<td[\w\W][^>]+><div align='center'>(房号:[\d]{2}[A-Za-z]{1})</div>[\s]*<div align='center'><a href='([\w\W][^']+)'";
Regex r = new Regex(strKey);
Regex rSub = new Regex(strSubKey);
if (r.IsMatch(strHtml))
{
MatchCollection mc = r.Matches(strHtml);
foreach (Match m in mc)
{
//层次
Console.WriteLine(m.Result("$1"));
this.textBox1.AppendText(m.Result("$1") + Environment.NewLine);
//房间号
string strRooms = m.Result("$2");
if (rSub.IsMatch(strRooms))
{
MatchCollection mcSub = rSub.Matches(strRooms);
foreach (Match ms in mcSub)
{
Console.WriteLine(ms.Result("$1"));
this.textBox1.AppendText(ms.Result("$1") + Environment.NewLine);
Console.WriteLine(ms.Result("$2"));
this.textBox1.AppendText(ms.Result("$2") + Environment.NewLine);
}
}
}
}
}
{
string strHtml = "<tr class='a1'>"
+ "<td width='84' rowspan='1' bgcolor='#EFF6FB'><div align='center'>13层</div></td> "
+ "<td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13A</div> <div align='center'><a href='housedetail.aspx?id=925352' target=_blank><img src='imc/b2.gif' border='0'></a></div></td>"
+ "<td height='68' width='140' bgcolor='#EFF6FB'><div align='center'>房号:13B</div> <div align='center'><a href='housedetail.aspx?id=925353' target=_blank><img src='imc/b1_2.gif' border='0'></a></div></td></tr>";
string strKey = @"<tr class='a1'>[\s]*<td[.\s][^>]+><div align='center'>([\d]+层)</div></td>([\w\W]+)</tr>";
string strSubKey = @"<td[\w\W][^>]+><div align='center'>(房号:[\d]{2}[A-Za-z]{1})</div>[\s]*<div align='center'><a href='([\w\W][^']+)'";
Regex r = new Regex(strKey);
Regex rSub = new Regex(strSubKey);
if (r.IsMatch(strHtml))
{
MatchCollection mc = r.Matches(strHtml);
foreach (Match m in mc)
{
//层次
Console.WriteLine(m.Result("$1"));
this.textBox1.AppendText(m.Result("$1") + Environment.NewLine);
//房间号
string strRooms = m.Result("$2");
if (rSub.IsMatch(strRooms))
{
MatchCollection mcSub = rSub.Matches(strRooms);
foreach (Match ms in mcSub)
{
Console.WriteLine(ms.Result("$1"));
this.textBox1.AppendText(ms.Result("$1") + Environment.NewLine);
Console.WriteLine(ms.Result("$2"));
this.textBox1.AppendText(ms.Result("$2") + Environment.NewLine);
}
}
}
}
}
展开全部
href='[^']+'
src='[^']+'
具体形式按你的Regex引擎来定,有可能是
href='(?[^']+)'
src='(?[^']+)'
src='[^']+'
具体形式按你的Regex引擎来定,有可能是
href='(?[^']+)'
src='(?[^']+)'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
发你邮箱了 希望对你有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
期待中。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询