Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi guys ,
i m lerning to coding UWP,but a lot of things i learnt doesnt work anymore?
could u guys help me?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace SplitViewApp5.Pages
{
    public partial class WebForm1 : System.Net.Http.HttpClient
    {
        protected void Page_Load(object sender, EventArgs e)
        {var html = new HtmlDocument();
            html.LoadHtml(new WebClient().DownloadString("http://www.google.com"));
            var root = html.DocumentNode;
            var tableNodes = root.Descendants("table");
            var items = new List<string>();
            foreach (var tbs in tableNodes.Select((tbNodes, i) => new { tbNodes = tbNodes, i = i }))


The compiler says that it couldn't find a class or namespace for Webclient,
i also tried Httpclient instead but its still doent work.
Thanx!

What I have tried:

i also tried Httpclient instead but its still doent work.
Posted
Updated 19-Oct-16 23:02pm
Comments
Kornfeld Eliyahu Peter 22-May-16 8:00am    
What between an UWP application and a web application?!

1 solution

Solution 1: Install-Package HtmlAgilityPack

[ Nuget package Link ]

Solution 2: Parsing Html

C#
private async void Parsing(string website)
       {
           try
           {
               HttpClient http = new HttpClient();
               var response = await http.GetByteArrayAsync(website);
               String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1);
               source = WebUtility.HtmlDecode(source);
               HtmlDocument resultat = new HtmlDocument();
               resultat.LoadHtml(source);

               List<HtmlNode> toftitle = resultat.DocumentNode.Descendants().Where
               (x => (x.Name == "div" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("block_content"))).ToList();

               var li = toftitle[6].Descendants("li").ToList();
               foreach (var item in li)
               {
                   var link = item.Descendants("a").ToList()[0].GetAttributeValue("href", null);
                   var img = item.Descendants("img").ToList()[0].GetAttributeValue("src", null);
                   var title = item.Descendants("h5").ToList()[0].InnerText;

                   listproduct.Add(new Product()
                   {
                       Img = img,
                       Title = title,
                       Link = link
                   });
               }

           }
           catch (Exception)
           {

               MessageBox.Show("Network Problem!");
           }

       }


Windows 8 Parsing Html using C# sample in C# for Visual Studio 2013[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900