C# 获得链接

//获得链接
            public ArrayList GetHyperLinks(string htmlCode)
            {
                ArrayList al = new ArrayList();
                string strRegex = "<a(.|\n)+?>";
                int startp, endp;
                Regex r = new Regex(strRegex, RegexOptions.IgnoreCase);
                MatchCollection m = r.Matches(htmlCode);
                for (int i = 0; i <= m.Count - 1; i++)
                {
                    bool rep = false;
                    string strNew = m[i].ToString();
                    // 过滤重复的URL
                    startp = strNew.ToLower().IndexOf("href=\"");
                    if (startp != -1)
                    {
                        startp = startp + 6;
                        endp = strNew.ToLower().IndexOf("\"", startp + 1);
                        strNew = strNew.Substring(startp, endp - startp);
                        foreach (string str in al)
                        {
                            if (strNew == str || strNew == "/" || strNew.Trim() == "")
                            {
                                rep = true;
                                break;
                            }
                        }
                        if (!rep) al.Add(strNew);
                    }
                }
                al.Sort();
                return al;
            }

你可能感兴趣的:(C#)