zoukankan      html  css  js  c++  java
  • Asp.Net正则获取页面a标签里的内容

    Asp.Net正则获取页面a标签里的内容

        string url = "http://www.114369.com";
            string html = MyCLib.NetClass.SendUrl(url,System.Text.Encoding.UTF8);
            List<string> keywords = new List<string>();
            Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""s>]+)1[^>]*>(?<text>(?:(?!</?a).)*)</a>");
            MatchCollection mc = reg.Matches(html);
            foreach (Match m in mc)
            {
                //richTextBox2.Text += m.Groups["url"].Value + "
    ";
                string keyword = Regex.Replace(m.Groups["text"].Value, "<[^>]*>", string.Empty).Replace("..", "").Replace("·", "").Replace("&nbsp;", "");
    
                if (keyword.Length > 0 && !keywords.Contains(keyword)) 
                {
                    keywords.Add(keyword);
                }
            }
            for (int i = 0; i < keywords.Count; i++)
            {
                Response.Write(keywords[i]);
                Response.Write("<br>");
            }

     Asp.Net正则过滤超链接a

    string s = "<a href="#">我们是中国人</a><a class='xxx' href="#">我们是中国人2</a>";
            Regex reg = new Regex(@"<as*[^>]*>([sS]+?)</a>", RegexOptions.IgnoreCase);
            s = reg.Replace(s, "$1");
            Response.Write(s);//结果:我们是中国人我们是中国人2

    js正则过滤超链接a

    string s = "<a href="#">我们是中国人</a><a class='xxx' href="#">我们是中国人2</a>";
    
    s = s.replace(/(</?a[^>]*>)(?!.*1)/ig,"");
  • 相关阅读:
    Mac OS 下包管理器 homebrew的安装
    草根程序员八年百万年薪之路
    div隐藏滚动条,仍可滚动
    感觉身体被掏空by彩虹室内合唱团
    添加bash命令
    mysql性能优化
    PHP变量存储结构
    轻量级MVC框架(自行开发)
    一致性hash算法之php实现
    redis安装
  • 原文地址:https://www.cnblogs.com/webapi/p/5711078.html
Copyright © 2011-2022 走看看