求个 过滤网页源码的 正则表达式解决方案
求个 过滤网页源码的 正则表达式
根据地址抓取的内容是上面的东西,求正则抓到 "本站主数据:湖北省武汉市 电信 参考数据一:湖北省武汉市 电信“
谢谢。
------解决方案--------------------
(?<=<td align="center"><ul class="ul1"><li>).*(?=</li></ul></td>)
------解决方案--------------------
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Value,"<[^>]*?>","");
------解决方案--------------------
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Groups[2].Value,"<[^>]*?>","");
------解决方案--------------------
如果是针对上面数据,
(?is)<table[^>]*>.*?<ul[^>]*class="ul1">\s*<li>(.*?)</li><li>(.*?)</li></ul>
直接去Groups[1].Value和Groups[2].Value即可
------解决方案--------------------
- HTML code
<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>
根据地址抓取的内容是上面的东西,求正则抓到 "本站主数据:湖北省武汉市 电信 参考数据一:湖北省武汉市 电信“
谢谢。
------解决方案--------------------
(?<=<td align="center"><ul class="ul1"><li>).*(?=</li></ul></td>)
------解决方案--------------------
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Value,"<[^>]*?>","");
------解决方案--------------------
string result=Regex.Replace(Regex.Match(yourhtml,@"(?is)<table[^>]*?>.*?<ul\sclass=(['""]?)ul1\1><li>(.*)</li></ul></td>").Groups[2].Value,"<[^>]*?>","");
------解决方案--------------------
如果是针对上面数据,
(?is)<table[^>]*>.*?<ul[^>]*class="ul1">\s*<li>(.*?)</li><li>(.*?)</li></ul>
直接去Groups[1].Value和Groups[2].Value即可
------解决方案--------------------
- C# code
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 ""; } }