A
A
Alexey Smirnov2016-02-16 16:41:23
HTML
Alexey Smirnov, 2016-02-16 16:41:23

What needs to be done in order for the program to work correctly with a "reference" indication of the path to the Html code?

Hello.
I'm trying to parse sites using HtmlAgilityPack.
For this I wrote the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Xml;
using System.IO;
using HtmlAgilityPack;

namespace ConsoleParsingHTMLwithHtmlAgilityPack_CSarp
{
    class Program
    {
        static void Main(string[] args)
        {
            HtmlDocument doc = new HtmlDocument();


            doc.LoadHtml(@"<html><body><div><table id=""foo""><tr><th>hello</th></tr><tr><td>world</td></tr></table></div><div><table class='mfd-table'><tr><th>hello222</th></tr><tr><td>world222</td></tr></table></div></body></html>");

            //doc.LoadHtml("mfd.ru/centrobank/correspondentaccountbalances/");


            var docNode = doc.DocumentNode;

            var x = docNode.SelectNodes("//table[@class='mfd-table']");

            Console.WriteLine(x);
            Console.ReadLine();

        }
    }
}

If I run the program for execution, when using the line of code:
doc.LoadHtml(@"<html><body><div><table id=""foo""><tr><th>hello</th></tr><tr><td>world</td></tr></table></div><div><table class='mfd-table'><tr><th>hello222</th></tr><tr><td>world222</td></tr></table></div></body></html>");

then the console displays: "HtmlAgilityPack.HtmlNodeCollection" - for me this is a sign that everything is working fine.
But if I replace the previous line in the program with the line:
doc.LoadHtml("mfd.ru/centrobank/correspondentaccountbalances/");

then when the program is executed, nothing is displayed in the console - for me this is a sign of incorrect operation of this program.
What needs to be done in order for the program to work correctly with a "reference" indication of the path to the Html code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2016-02-16
@ERAFY

Apparently the problem is that you do not see the difference between the path to the html code and the http-get request.
stackoverflow.com/questions/18269983/c-sharp-htmla... - Here's a better example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question