如何在asp.net中获取html标签的子内容信息 [英] How do I get the child content information of html tag in asp.net

查看:99
本文介绍了如何在asp.net中获取html标签的子内容信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求获取子标记内容..有要求



I have a requirement of getting child tag content..here is requirement

<div>
<p>78.90KB
<a rel="nofollow" href="https://developers.google.com/speed/articles/web-metrics" target="_blank">average is 320 Kb</a>
</p>
</div>



这里我只想获得78.90KB ...但根据我的代码,我得到了整个< p>标签也是< a>标签......实际上我不需要< a>标签

这里是我的c#代码....首先我得到< div> html的标签,我正在循环< div>用于搜索< p>的标签标签....




here i want to get only 78.90KB...but as per my code i am getting entire <p> tag with also <a> tag...actually i don't need <a> tag
here is my c# code....first i am getting <div> tags of html and i am looping the <div> tag for searching the <p> tag....

List<string> pagesize = new List<string>();

           string _pattern = @"\s*(.+?)\s*"
  string _pattern1=@"\s*(.+?)\s*";
 string _headPattern = string.Format("<div class=\"part text \">{0}</div>", _pattern);
         string _childpattern=string.Format("<p itemprop=\"fileSize\">{0}</p>",_pattern1);

         Match _match = Regex.Match(data, _headPattern, RegexOptions.Multiline);
         MatchCollection _match1 = Regex.Matches(data,_headPattern,RegexOptions.Multiline);
 foreach (Match tElement in _match1)
            {
                string element = tElement.Groups[1].Value;
              
                if (element==_childpattern)
                {
                    element = element.Replace("<p>", string.Empty);
                    element = element.Replace("</p>",string.Empty);
                    pagesize.Add(element);
                  
                }
                    
               
            }

          return PageSize = pagesize[0];       
       }



有什么方法可以得到我需要的元素.....请任何建议或建议.......: )


is there any way to get only the element which i need.....please any suggestions or advices.......:)

推荐答案

使用Jquery执行此操作:

Use Jquery to do this:
<script type="text/javascript">


(document).ready(function(){
alert(
(document).ready(function () { alert(


('div p')。first()。contents ()。eq(0).text());
});
< / script >
('div p').first().contents().eq(0).text()); }); </script>



问候..


Regards..


这篇关于如何在asp.net中获取html标签的子内容信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆