关于.net页面抓取的问题,跪求!!! 本帖最后由 a57397873 于 2010-08-03 10:14:23 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Regex htmlRegex = new Regex(@"<a [target=\"_blank\"][^>]*>(?<Content>[^<]*)</a>");你试下 /// <summary> /// 返回超连接的数组 /// 3、提取网页的链接,包括href和frame及iframe /// </summary> /// <param name="userInput"></param> /// <param name="WebText"></param> /// <returns></returns> public string[] Get_url_Array(string userInput, string WebText) { MatchCollection mc = Regex.Matches(WebText, userInput, RegexOptions.IgnoreCase); ArrayList Url_List = new ArrayList(); foreach (Match m in mc) { Url_List.Add(m.Value); } return (string[])Url_List.ToArray(typeof(string)); } string str = "===<a href=\"../p/20100621_4245.htm\" target=\"_blank\" title=\"“梦回1980” 专场演唱会\">“梦回1980” 专场演唱会</a>=="; //string str = "===<a href=\"../p/20100621_4245.htm\" title=\"“梦回1980” 专场演唱会\">“梦回1980” 专场演唱会</a>=="; Regex re = new Regex("<a([^>]*(?=target))*(target=\"(?<name>[^\"]*)\"[^>]*)?[^>]*>[^<|^>]*</a>"); GroupCollection gc = re.Matches(str)[0].Groups; if (gc["name"] != null) { Console.WriteLine(gc["name"]); } //Console.WriteLine(re.Matches(str).Count); //for (int i = 0; i < gc.Count; i++) //{ // Console.WriteLine(gc[i].Value + "="); //}仓促写的,不要嘲笑 asp.net gridview分页 带回复功能的留言板。。 想实现这样的“从主”效果要怎么办? 紧急求助:如何在aspx页面中插入代码? URL重写,GridView分页的问题.请教各位. 关于上传文件 file vs.net 2005中怎么调用自己写的类啊?我没分了 高手進來瞧瞧 无法调试? vb的代码怎么转成c#的 继续求助JS里用string赋值 嵌套datalist中的datalist使用第三方分页控件分页aspnetpager的问题
你试下
/// <summary>
/// 返回超连接的数组
/// 3、提取网页的链接,包括href和frame及iframe
/// </summary>
/// <param name="userInput"></param>
/// <param name="WebText"></param>
/// <returns></returns>
public string[] Get_url_Array(string userInput, string WebText)
{
MatchCollection mc = Regex.Matches(WebText, userInput, RegexOptions.IgnoreCase);
ArrayList Url_List = new ArrayList();
foreach (Match m in mc)
{
Url_List.Add(m.Value);
}
return (string[])Url_List.ToArray(typeof(string));
}
//string str = "===<a href=\"../p/20100621_4245.htm\" title=\"“梦回1980” 专场演唱会\">“梦回1980” 专场演唱会</a>=="; Regex re = new Regex("<a([^>]*(?=target))*(target=\"(?<name>[^\"]*)\"[^>]*)?[^>]*>[^<|^>]*</a>"); GroupCollection gc = re.Matches(str)[0].Groups; if (gc["name"] != null)
{
Console.WriteLine(gc["name"]);
} //Console.WriteLine(re.Matches(str).Count);
//for (int i = 0; i < gc.Count; i++)
//{
// Console.WriteLine(gc[i].Value + "=");
//}
仓促写的,不要嘲笑