0

I am trying to output some strings from a certain website and i want to add each row into a List. The output i am looking for looks like this:

string url = "https://thepiratebay.org/search/rick%20and%20morty/0/99/0";
        HtmlWeb web = new HtmlWeb();
        HtmlDocument doc = web.Load(url);

        //upload list
        List<string> uploadList = new List<string>();

foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[@id='searchResult']/tr/td/font[@class='detDesc']"))
        {
            var input =  node.InnerHtml.ToString();
            //The [^0-9] expression is used to find any character that is NOT a digit, will replace with empty string
            input = Regex.Replace(input, "([^0-9]+)"," ");

            Console.WriteLine(input);
         }

I need to store every row into a list in order to process each element of data and i can't manage to set doc.DocumentNode.SelectNodes("//table[@id='searchResult']/tr/td/font[@class='detDesc']") into an array

Răzvan Bălan
  • 33
  • 1
  • 13

1 Answers1

0

You can add your input into the list by using

uploadList.Add(Input);

in the foreach loop instead of printing it to the console and the somehow read it from there again.

And you might want to select the tr, td and font children as described in: https://stackoverflow.com/a/15004032/2960293

Community
  • 1
  • 1
Flurin
  • 98
  • 1
  • 10
  • i did exactly like this. i forgot to answer the question. Other than this, I also modified the regex a little, so if you want to see the output, here it is: ` foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[@id='searchResult']/tr/td/font[@class='detDesc']")) { string input = Regex.Replace(node.InnerHtml.ToString(), @"(?s)^.*?(\d{2})\D*(\d{2})\D*(\d{4}).*", "$1 $2 $3") uploadList.Add(input)` – Răzvan Bălan Feb 11 '17 at 07:12