求个 过滤网页源码的 正则表达式

a12321321321312321 2012-06-11 05:55:47

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><h3>ip138.com IP查询(搜索IP地址的地理位置)</h3></td>
</tr>
<tr>
<td align="center"><h1>您查询的IP:111.174.91.11</h1></td>
</tr>
<tr>
<td align="center"><ul class="ul1"><li>本站主数据:湖北省武汉市 电信</li><li>参考数据一:湖北省武汉市 电信</li></ul></td>
</tr>
<tr>
<td align="center">如果您发现查询结果不详细或不正确,请使用<a href="ip_add.asp?ip=111.174.91.101"><font color="#006600"><b>IP数据库自助添加</b></font></a>功能进行修正<br/><br/>
<iframe src="/jss/bd_460x60.htm" frameborder="no" width="460" height="60" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br/><br/></td>
</tr>
<form method="get" action="ips1388.asp" name="ipform" onsubmit="return checkIP();">
<tr>
<td align="center">IP地址或者域名:<input type="text" name="ip" size="16"> <input type="submit" value="查询"><input type="hidden" name="action" value="2"></td>
</tr><br>
<br>
</form>
</table>


根据地址抓取的内容是上面的东西,求正则抓到 "本站主数据:湖北省武汉市 电信 参考数据一:湖北省武汉市 电信“

谢谢。
...全文
131 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
丶Xiang 2012-06-11
  • 打赏
  • 举报
回复

public static string GetIPAddress(string data)
{
Regex Reg = new Regex("<td align=\"center\"><ul class=\"ul1\"><li>(.*?)</li><li>(.*?)</li></ul></td>");
Match Match = Reg.Match(data);
if (Match != null && Match.Success)
{ return Match.Groups[1].Value + " " + Match.Groups[2].Value; }
else { return ""; }
}
EnForGrass 2012-06-11
  • 打赏
  • 举报
回复
如果是针对上面数据,
(?is)<table[^>]*>.*?<ul[^>]*class="ul1">\s*<li>(.*?)</li><li>(.*?)</li></ul>
直接去Groups[1].Value和Groups[2].Value即可
q107770540 2012-06-11
  • 打赏
  • 举报
回复
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Groups[2].Value,"<[^>]*?>","");
q107770540 2012-06-11
  • 打赏
  • 举报
回复
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Value,"<[^>]*?>","");
cnfixit 2012-06-11
  • 打赏
  • 举报
回复
(?<=<td align="center"><ul class="ul1"><li>).*(?=</li></ul></td>)

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧