Thursday, June 19, 2014

How to get dropdown list from html by Html Agility Pack

private List GetDropdownList(string HtmlSource, string selectName)
        {
            HtmlDocument doc = new HtmlDocument();
            HtmlNode.ElementsFlags.Remove("option");
            doc.LoadHtml(HtmlSource);
            return doc.DocumentNode.SelectNodes(string.Format("//select[@name='{0}']//option", selectName)).Select(v => v.Attributes["value"].Value).ToList();
        }
Need to add HtmlNode.ElementsFlags.Remove("option");
before loading html source.

No comments:

Post a Comment