Error reading HTM file for HTML conversion to JSON file

Asked

Viewed 46 times

2

In this Topic I created

Been asked how to download zip file from Box server and unzip it on my hosting service which occurs perfectly.

After the previous events described, I want to read the html, but this giving file location error;

Unable to locate a part of the path 'C: Program Files (x86) IIS Express Content decompress D_MEGA.HTM'.

Error occurs on this line:

string page = webClient.DownloadString("Content/descompacta/D_MEGA.HTM");

I want to read the HTML and convert it to JSON

Code below the function I am developing, I would also like to analyze to see if there is redundancy in relation to the Httpclient and Webclient classes

public async Task<ActionResult> Index()
{
            HttpClient web = new HttpClient();
            string url = "http://www1.caixa.gov.br/loterias/_arquivos/";
            url += "loterias/D_megase.zip";
            byte[] data = await web.GetByteArrayAsync(url);
            System.IO.File.WriteAllBytes(Server.MapPath("Content/zip/megasena.zip"), data);
            ZipFile.ExtractToDirectory(Server.MapPath("Content/zip/megasena.zip"), Server.MapPath("Content/descompacta/"));

            WebClient webClient = new WebClient();
            string page = webClient.DownloadString("Content/descompacta/D_MEGA.HTM");

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(page);

            List<List<string>> table = doc.DocumentNode.SelectSingleNode("//table[@class='mydata']")
                        .Descendants("tr")
                        .Skip(1)
                        .Where(tr => tr.Elements("td").Count() > 1)
                        .Select(tr => tr.Elements("td").Select(td => td.InnerText.Trim()).ToList())
                        .ToList();


            return View();
        }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.