<ul class="mct">
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515" target="_blank">[1]</a>
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515" target="_blank">[2]</a>
</ul>
如何用正则取出href里的内容?
Regex reg_file = new Regex(@"<a href=""(.*?)"" target=""_blank"">[(.*?)]</a>");
我这样写有问题吗?
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515" target="_blank">[1]</a>
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515" target="_blank">[2]</a>
</ul>
如何用正则取出href里的内容?
Regex reg_file = new Regex(@"<a href=""(.*?)"" target=""_blank"">[(.*?)]</a>");
我这样写有问题吗?
解决方案 »
- 关于级联查询的问题。。。。。求解
- 如何使用.net编写上传视频功能
- visio 2005有下载吗,怎么下的是2005,安装后是2003,visio2005有可以生成数据库的版本吗(2003可以)
- 一个关于DropDownList的问题
- 2005 下面如何引用IEWebControl
- 用c#做的asp.net,查询是没问题,可是增删改都不行。用的是System.Data.Odbc.
- datagrid不能分页了
- 好奇怪的问题!RadioButtonList绑定后获取不到正确的选项!
- 论持久层开发..........................
- ADO.NET数据库绑定的问题
- vs2010打开 2.0项目出现问题,C#项目针对的是”.net framework,Version=v2.0″,但此计算机上没有安装它。
- 如何取以xml格式中节点之间的值
貌似转义一下就可以了
void Main()
{
string html=@"<ul class=""mct"">
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
</ul>";
foreach(Match m in Regex.Matches(html,@"<a[^>]*?href=(['""])?(?<href>[^'""]+)\1[^>]*>"))
{
Console.WriteLine(m.Groups["href"].Value);
}
}/*
../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515
../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515
*/
<div class="l side">
<div id="tools">
<h3>::实用工具::</h3>
<ul>
<li><a href="http://tool.115.com/live/speed" target="_blank">上网测速</a></li>
<li><a href="http://tool.115.com/shouji/" target="_blank">手机查询</a></li>
<li><a href="http://tool.115.com/live/huoche/" target="_blank">火车时刻</a></li>
<li><a href="http://tool.115.com/ip/" target="_blank">I P 地址</a></li>
<li><a href="http://aq.115.com" target="_blank">免费杀毒</a></li>
<li><a href="http://tool.115.com/live/express/" target="_blank">快递查询</a></li>
<li><a href="http://tool.115.com/tianqi/" target="_blank">天气预报</a></li>
<li><a href="http://tool.115.com/live/fanyi/" target="_blank">在线翻译</a></li>
<li><a href="http://tool.115.com/live/ditu/" target="_blank">城市地图</a></li>
<li><a href="http://tool.115.com/youbian/" target="_blank">邮编区号</a></li>
</ul>
</div>
<div id="msrc">
<h3>::影片搜索::</h3>
<form name="form" action="/files/search.php" method="post" target="_blank">
选择类型 <span class="select">
<select name="typeid">
<option value="title">电影名称</option>
<option value="actor">演员名称</option>
</select>
</span>
<div id="search">
关键字 <input type="text" name="keyword" class="k" />
<input type="submit" value="影片搜索" onClick="if (form.keyword.value.length==0) {alert('请输入关键字!');return false;}" class="btn" /></div>
<div id="search_auto"></div>
</form>
</div>
<!--
<div class="slist" id="new">
<h3>::最近更新::</h3>
<ul>
<script src="../js/news.js"></script>
</ul>
</div>
-->
<div class="slist" id="order"> </div>
<div class="slist" id="re_soft">
<h3>::相关软件::</h3>
<div class="con"><a href="/movie_2004/index/qvodsetup.htm" target="_blank"><img src="http://pic.66fzl.com/newimages/qvod_logo.jpg" /></a><br />
<a href="http://update.qvod.com/QvodPal.exe" target="_blank">Qvod解码器伴侣包</a><br />
<a href="http://update.qvod.com/xpsp2patch.exe" target="_blank">XPSP2连接数限制补丁</a></div>
</div>
</div>
<div class="r" id="mcon">
<div class="s115">
<form action="http://v.115.com/" method="get" target="_blank" id="s115" name="s115">
<a href="http://v.115.com/" target="_blank"><img src="http://pic.66fzl.com/images/tom365_v115.gif" /></a>
<input name="q" id="q" type="text" value="" class="txt" />
<input name="" type="image" src="http://pic.66fzl.com/images/search_button.gif" alt="影视聚搜" />
</form>
<div class="hotag r">
<script type="text/javascript" src="http://www.96693.com/tg/tom365/a4-txt/text.js"></script>
</div>
</div>
<!---->
<div id="shenfenid">
<style type="text/css">
#shenfenid{ line-height:24px; padding:0 8px 0 25px; border:1px solid #81B316; background:url(http://pic.66fzl.com/images/icon_01.gif) no-repeat 4px 4px; }
#shenfenid a{ color:#F00; }
</style>
防止诈骗,赶紧使用“<a href="http://tool.115.com/live/idcard/" target="_blank">身份证真伪查询/身份证号码验证查询</a>”验明正身。</div>
<!---->
<div class="movie"><img src="http://pic.66fzl.com/imgs/liehuozhanche.jpg" class="mp" />
<ul>
<li>片 名:<strong id="mname">烈火战车[1国语版,2粤语版][BD版本]</strong></li>
<li>年 代:1995</li>
<li>地 区:香港</li>
<li>类 型:<a href="../mlist/1_1.html">动作片</a></li>
<li>导 演:尔冬升</li>
<li>主 演:刘德华 梁咏琪 吴大维 秦沛</li>
<li>上传日期:2011-01-12</li>
</ul>
<div class="cbn"><div id="m">
<style>
#m {border:10px solid #EEFFAD; width:369px; font-size:12px;}
#m ul{ width:367px; height:41px; border:1px solid #C3EF2A}
#m ul,#m li { margin:0 ; padding:0 ; list-style:none;}
#m li { float:left; width:170px; padding-left:13px; color:#72C603; overflow: hidden; line-height:20px;}
#m a { color:#3B591B; text-decoration:none}
#m a:hover { text-decoration:underline;}
</style>
<ul>
<script type="text/javascript" src="http://www.96693.com/tg/tom365/b1-txt1/text.js"></script>
</ul>
</div></div><div class="mcn"><script type="text/javascript" src="http://www.96693.com/tg/tom365/b2-59450/lunbo.js"></script></div>
<div class="mcn"><img alt="" src="http://pic.66fzl.com/images/qvod.gif" width="20" height="20" align="middle" /><font color="#3B591B"> QVOD播放 <a href="/movie_2004/index/qvodsetup.htm" target="_blank">QVOD播放器下载>></a></font></div><ul class="mct">
<li><a href="../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102" target="_blank">[1]</a><li><a href="../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102" target="_blank">[2]</a></ul>
<div class="mcn"><img alt="" src="http://pic.66fzl.com/images/qvod.gif" width="20" height="20" align="middle" /><font color="#3B591B"> QVOD备用模式播放(正常模式无法点播时使用)</font></div><ul class="mct">
<li><a href="../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515" target="_blank">[1]</a><li><a href="../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515" target="_blank">[2]</a></ul>
<div class="text_gg"><script type="text/javascript" src="http://www.96693.com/tg/tom365/b3-59460/lunbo.js"></script><br>
<script type="text/javascript" src="http://www.96693.com/tg/tom365/b4-txt2/text.js"></script></div>
<!--
<div class="copy">
</div>
你这样写也不行。因为我要从一堆的源码里取。
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
</ul>";
foreach (Match m in Regex.Matches(html, @"(?is)<a\b.+?href=""(?<href>[^""]+)""\starget=""_blank"">(?<text>.+?)</a>"))
{
Console.WriteLine(m.Groups["href"].Value);
Console.WriteLine(m.Groups["text"].Value);
}
string str = "<ul class=\"mct\"><li><a href=\"../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515\" target=\"_blank\">[1]</a>"
+ "<li><a href=\"../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515\" target=\"_blank\">[2]</a></ul>";
Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]*)\1[^>]*?>");
MatchCollection match = reg.Matches(str);
foreach (Match m in match)
{
result += m.Groups["href"].Value+"<br/>";
}
Response.Write(result);
转义
string html = @"<ul class=""mct"">
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
<li>
<a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
<li><a href=""xx.html"" target=""_blank"">xxx</a></li>
<li><a href=""yy.html"" target=""_blank"">[yyyy</a></li>
</ul>";
foreach (Match m in Regex.Matches(html, @"<a href=""(?<href>.*?)"" target=""_blank"">(?<text>\[.*?\])</a>"))
{
Console.WriteLine(m.Groups["href"].Value);
Console.WriteLine(m.Groups["text"].Value);
}
void Main()
{
string html=@"<div id=""main"">
<div class=""l side"">
<div id=""tools"">
<h3>::实用工具::</h3>
<ul>
<li><a href=""http://tool.115.com/live/speed"" target=""_blank"">上网测速</a></li>
<li><a href=""http://tool.115.com/shouji/"" target=""_blank"">手机查询</a></li>
<li><a href=""http://tool.115.com/live/huoche/"" target=""_blank"">火车时刻</a></li>
<li><a href=""http://tool.115.com/ip/"" target=""_blank"">I P 地址</a></li>
<li><a href=""http://aq.115.com"" target=""_blank"">免费杀毒</a></li>
<li><a href=""http://tool.115.com/live/express/"" target=""_blank"">快递查询</a></li>
<li><a href=""http://tool.115.com/tianqi/"" target=""_blank"">天气预报</a></li>
<li><a href=""http://tool.115.com/live/fanyi/"" target=""_blank"">在线翻译</a></li>
<li><a href=""http://tool.115.com/live/ditu/"" target=""_blank"">城市地图</a></li>
<li><a href=""http://tool.115.com/youbian/"" target=""_blank"">邮编区号</a></li>
</ul>
</div>
<div id=""msrc"">
<h3>::影片搜索::</h3>
<form name=""form"" action=""/files/search.php"" method=""post"" target=""_blank"">
选择类型 <span class=""select"">
<select name=""typeid"">
<option value=""title"">电影名称</option>
<option value=""actor"">演员名称</option>
</select>
</span>
<div id=""search"">
关键字 <input type=""text"" name=""keyword"" class=""k"" />
<input type=""submit"" value=""影片搜索"" onClick=""if (form.keyword.value.length==0) {alert('请输入关键字!');return false;}"" class=""btn"" /></div>
<div id=""search_auto""></div>
</form>
</div>
<!--
<div class=""slist"" id=""new"">
<h3>::最近更新::</h3>
<ul>
<script src=""../js/news.js""></script>
</ul>
</div>
-->
<div class=""slist"" id=""order""> </div>
<div class=""slist"" id=""re_soft"">
<h3>::相关软件::</h3>
<div class=""con""><a href=""/movie_2004/index/qvodsetup.htm"" target=""_blank""><img src=""http://pic.66fzl.com/newimages/qvod_logo.jpg"" /></a><br />
<a href=""http://update.qvod.com/QvodPal.exe"" target=""_blank"">Qvod解码器伴侣包</a><br />
<a href=""http://update.qvod.com/xpsp2patch.exe"" target=""_blank"">XPSP2连接数限制补丁</a></div>
</div>
</div>
<div class=""r"" id=""mcon"">
<div class=""s115"">
<form action=""http://v.115.com/"" method=""get"" target=""_blank"" id=""s115"" name=""s115"">
<a href=""http://v.115.com/"" target=""_blank""><img src=""http://pic.66fzl.com/images/tom365_v115.gif"" /></a>
<input name=""q"" id=""q"" type=""text"" value="""" class=""txt"" />
<input name="""" type=""image"" src=""http://pic.66fzl.com/images/search_button.gif"" alt=""影视聚搜"" />
</form>
<div class=""hotag r"">
<script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/a4-txt/text.js""></script>
</div>
</div>
<!---->
<div id=""shenfenid"">
<style type=""text/css"">
#shenfenid{ line-height:24px; padding:0 8px 0 25px; border:1px solid #81B316; background:url(http://pic.66fzl.com/images/icon_01.gif) no-repeat 4px 4px; }
#shenfenid a{ color:#F00; }
</style>
防止诈骗,赶紧使用“<a href=""http://tool.115.com/live/idcard/"" target=""_blank"">身份证真伪查询/身份证号码验证查询</a>”验明正身。</div>
<!---->
<div class=""movie""><img src=""http://pic.66fzl.com/imgs/liehuozhanche.jpg"" class=""mp"" />
<ul>
<li>片 名:<strong id=""mname"">烈火战车[1国语版,2粤语版][BD版本]</strong></li>
<li>年 代:1995</li>
<li>地 区:香港</li>
<li>类 型:<a href=""../mlist/1_1.html"">动作片</a></li>
<li>导 演:尔冬升</li>
<li>主 演:刘德华 梁咏琪 吴大维 秦沛</li>
<li>上传日期:2011-01-12</li>
</ul>
<div class=""cbn""><div id=""m"">
<style>
#m {border:10px solid #EEFFAD; width:369px; font-size:12px;}
#m ul{ width:367px; height:41px; border:1px solid #C3EF2A}
#m ul,#m li { margin:0 ; padding:0 ; list-style:none;}
#m li { float:left; width:170px; padding-left:13px; color:#72C603; overflow: hidden; line-height:20px;}
#m a { color:#3B591B; text-decoration:none}
#m a:hover { text-decoration:underline;}
</style>
<ul>
<script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b1-txt1/text.js""></script>
</ul>
</div></div><div class=""mcn""><script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b2-59450/lunbo.js""></script></div>
<div class=""mcn""><img alt="""" src=""http://pic.66fzl.com/images/qvod.gif"" width=""20"" height=""20"" align=""middle"" /><font color=""#3B591B""> QVOD播放 <a href=""/movie_2004/index/qvodsetup.htm"" target=""_blank"">QVOD播放器下载>></a></font></div><ul class=""mct"">
<li><a href=""../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102"" target=""_blank"">[1]</a><li><a href=""../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102"" target=""_blank"">[2]</a></ul>
<div class=""mcn""><img alt="""" src=""http://pic.66fzl.com/images/qvod.gif"" width=""20"" height=""20"" align=""middle"" /><font color=""#3B591B""> QVOD备用模式播放(正常模式无法点播时使用)</font></div><ul class=""mct"">
<li><a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a><li><a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a></ul>
<div class=""text_gg""><script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b3-59460/lunbo.js""></script><br>
<script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b4-txt2/text.js""></script></div>
<!--
<div class=""copy"">
</div>
";
foreach(Match m in Regex.Matches(html,@"<a[^>]*?href=(['""])?(?<href>[^'""]+)\1[^>]*>"))
{
Console.WriteLine(m.Groups["href"].Value);
}
}/*
http://tool.115.com/live/speed
http://tool.115.com/shouji/
http://tool.115.com/live/huoche/
http://tool.115.com/ip/
http://aq.115.com
http://tool.115.com/live/express/
http://tool.115.com/tianqi/
http://tool.115.com/live/fanyi/
http://tool.115.com/live/ditu/
http://tool.115.com/youbian/
/movie_2004/index/qvodsetup.htm
http://update.qvod.com/QvodPal.exe
http://update.qvod.com/xpsp2patch.exe
http://v.115.com/
http://tool.115.com/live/idcard/
../mlist/1_1.html
/movie_2004/index/qvodsetup.htm
../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102
../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102
../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515
../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515*/