I have the following code that I managed to come up with:
private void button1_Click(object send开发者_JS百科er, EventArgs e)
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
using (var o = new OpenFileDialog())
{
if (o.ShowDialog() == DialogResult.OK)
doc.Load(o.FileName);
}
foreach (HtmlAgilityPack.HtmlAttribute att in doc.DocumentNode.Attributes)
{
label1.Text += Environment.NewLine +
att.Name + " " + att.Value;
}
}
But it's not doing anything. There are no errors, no exceptions, and it compiles and runs. But, as you can see, from inside the foreach loop, it is supposed to keep adding found attributes and their values to the label1.Text control, but it isn't. Nothing happens!
Am I doing something wrong? Can someone please help?
Thank you
By iterating over doc.DocumentNode.Attributes
, you are trying to get attributes of the root element (DocumentNode
) which is a placeholder containing your <html>
tag (and possibly some adjacent nodes like comments and white space). Which does not make a lot of sense.
What are you trying to extract exactly?
精彩评论