如何获得源文件中的链接

louxuejiao 2012-06-08 06:06:44
<h3><a href="http://www.edeng.cn/13/jiaju/" target="_blank" >家居黄页</a></h3>
<p><a href="http://www.edeng.cn/13/riyongbaihuo/" title="日用百货" target="_blank" >日用百货</a>
|<a href="http://www.edeng.cn/13/jiajuzhuangshi/" title="家居装饰" target="_blank" >
已经获得了源代码GetSource,源文件中有如上代码,我现在要写个方法,就是要获得所有的链接,并且没有title属性的链接要删除掉,然后把得到的链接存进数据库。

最后得到的结果应该是如下:
http://www.edeng.cn/13/riyongbaihuo/
http://www.edeng.cn/13/jiajuzhuangshi/

最好是能用substring进行截取
本人是新手,希望大家多多帮忙啊,多加点注释
...全文
50 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx
string pattern = @"(?i)<a[^>]+?href=(['""]?)([^'""]+)\1[^>]+?title[^>]+?>";
string[] ss = Regex.Matches(tempStr,pattern).Cast<Match>().Select(a=>a.Groups[2].Value).ToArray();
/*
* [0] "http://www.edeng.cn/13/riyongbaihuo/" string
[1] "http://www.edeng.cn/13/jiajuzhuangshi/" string

*/

111,126

社区成员

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

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

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