Simple Code to Using Html Agility Pack
So i have a code of Htmlagilitypack in my mind and hopefully what I get can be useful for those.
Lest try!
Do not forget to add this code in your reference :
using HtmlAgilityPack;
This is firs time, we will take the example of html and put it into the HTML Agility Pack
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(sampleHtml);
Get Text Box Value
HtmlAgilityPack.HtmlNode node = new HtmlAgilityPack.HtmlNod();
node = doc.DocumentNode.SelectSingleNode("//input[@id='nameOfId']");
string strValue = node.Attributes["value"].value;
Get Combo Box Text Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectSingleNode("//select[@id='nameOfId']").Elements("option"))
{
If(node.Attributes["selected"] != null)
{
strValue = node.Attributes["value"].value;
break;
}
}
Get Radio Button Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//input[@name='nameOfName']"))
{
if (node.Attributes["checked"] != null)
{
strValue = node.Attributes["value"].value;
break;
}
}
Oh, too many in my mind so that I do not remember it clearly. I will update when I get something else or If you need somethings about it you can comment this article and I will answer as soon.
So i have a code of Htmlagilitypack in my mind and hopefully what I get can be useful for those.
Lest try!
Do not forget to add this code in your reference :
using HtmlAgilityPack;
This is firs time, we will take the example of html and put it into the HTML Agility Pack
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(sampleHtml);
Get Text Box Value
HtmlAgilityPack.HtmlNode node = new HtmlAgilityPack.HtmlNod();
node = doc.DocumentNode.SelectSingleNode("//input[@id='nameOfId']");
string strValue = node.Attributes["value"].value;
Get Combo Box Text Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectSingleNode("//select[@id='nameOfId']").Elements("option"))
{
If(node.Attributes["selected"] != null)
{
strValue = node.Attributes["value"].value;
break;
}
}
Get Radio Button Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//input[@name='nameOfName']"))
{
if (node.Attributes["checked"] != null)
{
strValue = node.Attributes["value"].value;
break;
}
}
Oh, too many in my mind so that I do not remember it clearly. I will update when I get something else or If you need somethings about it you can comment this article and I will answer as soon.