[英]Parse Html file using html agility pack c#
I want to find values of all type in an html code. 我想在html代码中查找所有类型的值。 I used html agility pack here is my code:
我使用了HTML敏捷包,这是我的代码:
doc.Load(resp.GetResponseStream());
foreach (HtmlNode input in doc.DocumentNode.SelectNodes("//input"))
{
HtmlAttribute value = input.Attributes["value"];
Console.WriteLine(value);
}
the output of the code is just htmlagilitypack.htmlattribute. 代码的输出只是htmlagilitypack.htmlattribute。 can you tell me what it is?
你能告诉我这是什么吗?
Represents HTML tag attribute. 表示HTML标签属性。 If you need a value of it, you must use its
Value
property. 如果需要它的值,则必须使用其
Value
属性。
For example: 例如:
doc.Load(resp.GetResponseStream());
foreach (HtmlNode input in doc.DocumentNode.SelectNodes("//input"))
{
HtmlAttribute attr = input.Attributes["value"];
if (attr != null)
Console.WriteLine(attr.Value);
}
For HTML: 对于HTML:
<input type=text name="myInput" value="Come get some!" />
output will be: Come get some!
输出将是:
Come get some!
EDIT: Null check added 编辑:添加空检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.