简体   繁体   English

如何从HtmlDocument对象过滤隐藏字段?

[英]How can I filter hidden fields from an HtmlDocument object?

I have loaded an HtmlDocument using HtmlWeb . 我已经装了HtmlDocument使用HtmlWeb I understand I can get all the hidden input fields using the SelectNodes() method. 我知道我可以使用SelectNodes()方法获取所有隐藏的输入字段。 But I don't want to get all the hidden input like "__VIEWSTATE" or "__EVENTTARGET". 但是我不想获取所有隐藏的输入,例如“ __VIEWSTATE”或“ __EVENTTARGET”。 how can i filter them? 我该如何过滤它们?

Code: 码:

    HtmlWeb web = new HtmlWeb();
    HtmlDocument doc = web.Load(url);

    HtmlNodeCollection hiddenFieldNodes = doc.DocumentNode.SelectNodes("//input[@type='hidden']");

Edit: Is there any XPath I can apply to filter among hidden input fields? 编辑:是否有任何XPath可以应用于在隐藏的输入字段之间进行过滤?

You can ignore any of the Asp.NET special hidden fields, with the following xpath . 您可以使用以下xpath忽略任何Asp.NET特殊隐藏字段。 All of their special fields have names starting with two underscores: 其所有特殊字段的名称都以两个下划线开头:

HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);

HtmlNodeCollection visibleFieldNodes = doc.DocumentNode.SelectNodes("//input[not(starts-with(@name, '__'))]");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM