HTML敏捷性包获得所有输入字段 [英] HTML Agility Pack get all input fields

查看:161
本文介绍了HTML敏捷性包获得所有输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在互联网上的一些代码,查找所有的href 标签,并将其更改为google.com,但我怎么能告诉代码查找所有的输入字段,并把自定义文本在那里?

I found some code on the internet that finds all the href tags and changes them to google.com, but how can I tell the code to find all the input fields and put custom text in there?

这是代码,我现在所拥有的:

This is the code I have right now:

HtmlDocument doc = new HtmlDocument();
doc.Load(path);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
    HtmlAttribute att = link.Attributes["href"];
    att.Value = "http://www.google.com";
}
doc.Save("file.htm");

请,有人可以帮助我,我似乎无法找到这个在互联网上的任何信息:(

Please, can someone help me, I can't seem to find any information about this on the internet :(.

推荐答案

更改XPath的选择器 //输入来选择所有输入节点:

Change the XPath selector to //input to select all the input nodes:

foreach (HtmlNode input in doc.DocumentNode.SelectNodes("//input"))
{
    HtmlAttribute att = input.Attributes["value"];
    att.Value = "some text";
}

这篇关于HTML敏捷性包获得所有输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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