I am making an automation application using Html Agility Pack for a website. Each product on the website has a different html code for size and I'm trying to get that code from a product.
This is the website and an example product: Click here
Here is my current code:
var webGet = new HtmlWeb();
var doc = webGet.Load(txtLink.Text);
HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//*[contains(@id,'size')]");
foreach (var node in collection)
{
var Size = node.InnerHtml.ToString();
txtLog.Text += Environment.NewLine + Size;
}
Here is the response for the example product:
<option value="33455">Small
<option value="33456">Medium
<option value="33457">Large
<option value="33458">XLarge
If you don't want to check the website this is what the html code looks like for an item:
<select name="size" id="size"><option value="33455">Small</option>
<option value="33456">Medium</option>
<option value="33457">Large</option>
<option value="33458">XLarge</option>
</select>
What I want to happen:
I enter the product link for an item and select a size. If the size selected is found then return the size code for that size only. For example I use the example item and select Medium so the application should return 33456.