Answer the question
In order to leave comments, you need to log in
How to solve the problem with the error: "Object reference does not point to an instance of an object"?
I do HTML parsing using HtmlAgilityPack.
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)
{
string pathToHtml = "C:/Users/alex/Desktop/view-source_gtmarket.ru_news_2015_04_24_7130.html";
System.IO.StreamReader HtmlDoc = new System.IO.StreamReader(pathToHtml);
string content = HtmlDoc.ReadToEnd();
HtmlDoc.Close();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
var x = doc.DocumentNode.SelectNodes("//table[@class='table-data']").Elements("tr").ToList();
foreach (HtmlNode node in x)
{
var s = node.Elements("td").ToList();
foreach (HtmlNode item in s)
{
Console.Write(" " + item.InnerText);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
var x = doc.DocumentNode.SelectNodes("//table[@class='table-data']").Elements("tr").ToList();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question