HTM file reading error for HTML conversion to JSON file

2

In this Topic that I created

I was asked how to download the zip file from the Mailbox server and unzip it to my perfectly hosting service .

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

Could not find a part of the 'C: \ Program Files (x86) \ IIS Express \ Content \ decompress \ D_MEGA.HTM' path

The 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'm developing, I would also like to look at whether there is no redundancy with 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();
        }
    
asked by anonymous 02.11.2017 / 02:24

0 answers