获取一个网页的P标签的内容,例如<p>测试</p>,截取“测试”,如果文本有其他网页标签也要去除,只剩p标签的内容

解决方案 »

  1.   

    Regex reg=new Regex("(?is)<p>(?<content>.*?)</p>");
    string result=string.Empty;
    foreach(Match m in reg.Matches("你的网页代码"))
    {
     result+=m.Groups["content"].Value+"\r\n";
    }
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
            {
                string s = @"<p>测试<span>sdlfasdf</span> </p>";            //第一步: 获取P标签的内容
                Regex reg = new Regex("<p>(.*)(</p>)");
                string s1 = reg.Match(s).Groups[1].Value;
                
                //第二步:清除内容中的Html标记
                string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "<[^>]*?>", "");
                //s2就是结果
                Response.Write(s2);
            }
      

  3.   

    去掉文本中的标签,最后加上这句:
    result=Regex.Replace(result,"<[^>]*>","");//去掉标签,如<font>
      

  4.   

    请min_jie  到这回帖回复一下,分全给你极域电子教室学生演示模块怎样做?(顶贴有分)