0

I have a NewAccount class:

public class NewAccount
    {
        public string Name { get; set; }
        public string NewName { get; set; }
       ...
    }

and I have code that goes to get data to an excel and puts it on my list. What I wanted to do now was: every name on my list do a search on a website and remove a piece of HTML on a page with HTML Agility Pack. my code:

 private static void GetData(List<NewAccount> people)
        {
            try
            {
                foreach (var dt in people)
                {
                    var url = "https://www.racius.com/pesquisa/?q=" + dt.NewName;
                    string Node = "//div[@class='row results']";

                    HtmlWeb web = new HtmlWeb();
                    HtmlDocument doc = web.Load(url);
                    HtmlNode node = doc?.DocumentNode.SelectNodes(Node)?.First();

                    foreach (HtmlNode link in doc?.DocumentNode.SelectNodes("//p[@class='results__name']"))
                    {
                        string hrefValue = link.GetAttributeValue("p", string.Empty);
                        link.SetAttributeValue("p",  hrefValue);
                        Console.WriteLine(dt.NewName + "   " + link.InnerText ?? "");
                    }

                }

            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine(e);
            }

0 Answers0