想要采集verycd ,需要采集到链接,标题,更新时间,自己写的正则在一个测试器里成功匹配到所有的值,但是放到c#程序里只能匹配到一个值。而且是最后一个值。 Regex reg = new Regex("<td class=xt>([\\s\\S]*)<a href=\"(?<url>.*?)\">(?<text>.*?)</a><br/>([\\s\\S]*)更新时间:(?<time>.*?) 点击");
MatchCollection mc = reg.Matches(ssstr);//ssstr就是下面的内容。采集到的richTextBox1.Text += "\r\n" + mc.Count + "****";//不管ssstr有多少实际数据,都只输出1
foreach (Match m in mc)
{
richTextBox1.Text += "\r\n" + m.Groups["url"].Value + " 时间:" + m.Groups["time"].Value;//输出最后一个值
}<td class=bt>摘要</td>
<td class=bt width=10%>作者</td>
</tr>
<tr bgcolor=#ffffff>
<td class=xt align=center><a href="/id/2724864"><img src="http://img.simplecd.org/image/2724864.jpg" title="《VOA Learning English_2011》[压缩包]" width=80 height=80/></a></td>
<td class=xt>
<a href="/id/2724864">《VOA Learning English_2011》[压缩包]</a><br/>
发行日期: 2011年对白语言: 英语文字语言: 英文<br/>
更新时间:2011/07/22 11:11:59 点击:2109559<br/>
</td>
<td class=xt><a href="/user/shenning64">shenning64</a></td>
</tr>
<tr bgcolor=#ffffff>
<td class=xt align=center><a href="/id/2880729"><img src="http://img.simplecd.org/image/2880729.jpg" title="《一起看动画》(Animation together)2011年首发动画类电子杂志[201106]第六期发布了!!!" width=80 height=80/></a></td>
<td class=xt>
<a href="/id/2880729">《一起看动画》(Animation together)2011年首发动画类电子杂志[201106]第六期发布了!!!</a><br/>
Douban5382879:8.9(2198 votes)发行时间: 2011年01月15日<br/>
更新时间:2011/07/22 09:51:58 点击:63180<br/>
</td>
<td class=xt><a href="/user/cgmentor">cgmentor</a></td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 align=center width=1000>
<tr><td align=center width=1000>
MatchCollection mc = reg.Matches(ssstr);//ssstr就是下面的内容。采集到的richTextBox1.Text += "\r\n" + mc.Count + "****";//不管ssstr有多少实际数据,都只输出1
foreach (Match m in mc)
{
richTextBox1.Text += "\r\n" + m.Groups["url"].Value + " 时间:" + m.Groups["time"].Value;//输出最后一个值
}<td class=bt>摘要</td>
<td class=bt width=10%>作者</td>
</tr>
<tr bgcolor=#ffffff>
<td class=xt align=center><a href="/id/2724864"><img src="http://img.simplecd.org/image/2724864.jpg" title="《VOA Learning English_2011》[压缩包]" width=80 height=80/></a></td>
<td class=xt>
<a href="/id/2724864">《VOA Learning English_2011》[压缩包]</a><br/>
发行日期: 2011年对白语言: 英语文字语言: 英文<br/>
更新时间:2011/07/22 11:11:59 点击:2109559<br/>
</td>
<td class=xt><a href="/user/shenning64">shenning64</a></td>
</tr>
<tr bgcolor=#ffffff>
<td class=xt align=center><a href="/id/2880729"><img src="http://img.simplecd.org/image/2880729.jpg" title="《一起看动画》(Animation together)2011年首发动画类电子杂志[201106]第六期发布了!!!" width=80 height=80/></a></td>
<td class=xt>
<a href="/id/2880729">《一起看动画》(Animation together)2011年首发动画类电子杂志[201106]第六期发布了!!!</a><br/>
Douban5382879:8.9(2198 votes)发行时间: 2011年01月15日<br/>
更新时间:2011/07/22 09:51:58 点击:63180<br/>
</td>
<td class=xt><a href="/user/cgmentor">cgmentor</a></td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 align=center width=1000>
<tr><td align=center width=1000>
没有想过要写三个语句。因为以前看过ET采集器,它就是一次采集所有想要的值。再仔细的看了一次,发现是自己在修修补补的时候使用了贪婪匹配。改动一下就搞定了。Regex reg = new Regex("<td class=xt>([\\s\\S]*?)<a href=\"(?<url>.*?)\">(?<text>.*?)</a><br/>([\\s\\S]*?)更新时间:(?<time>.*?) 点击");
Regex reg = new Regex(@"(?is)<td class=xt>\s*<a href=""(?<url>[^""]*?)""[^>]*>(?<text>[^<]*?)</a><br/>.*?更新时间:(?<time>.*?) 点击");