HTML Agility Pack 查找服务器控件 [英] HTML Agility Pack Find Server controls

查看:22
本文介绍了HTML Agility Pack 查找服务器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小的 c# 应用程序来搜索 aspx 页面中的 asp:TextBox 控件.

I am doing a small c# application to search asp:TextBox controls in aspx pages.

我想知道如何使用 HTML Agility Pack 在 aspx 页面中搜索所有 TextBox 控件.

I would like to know how can I search for all TextBox controls in aspx pages using HTML Agility Pack.

<asp:TextBox ID="txtSubjectName"  runat="server"/>

推荐答案

您可以使用 doc.DocumentNode.Descendants("asp:TextBox").请注意,Where 并不是真正需要的,但如果您需要所有服务器控件,而不仅仅是 TextBox:

You can use doc.DocumentNode.Descendants("asp:TextBox"). Note that the Where is not really needed but you can use it if you need all server controls not only TextBox:

var allTxt = doc.DocumentNode.Descendants("asp:TextBox")
    .Where(txt => txt.GetAttributeValue("runat", "").Equals("server", StringComparison.InvariantCultureIgnoreCase));

这假定您有一个要分析的 aspx 文本文件,而不是不包含服务器控件的呈现的 html.

This presumes that you have an aspx text file which you want to analyze and not the rendered html which doesnt contain server controls.

这篇关于HTML Agility Pack 查找服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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