2015-07-16 1 views
3

Existe-t-il un analyseur HTML utilisant X-Path pour UWP - Windows 10?Analyseur HTML pour Windows 10 (UWP)

Quelle est la meilleure/la meilleure façon d'explorer le langage HTML dans Windows 10?

+0

[htmlagilitypack] (https://htmlagilitypack.codeplex.com) – Graffito

+0

@Graffito N'a pas pris en charge ... Vous avez une erreur dans la méthode SelectNode ... Comme Windows Phone 8.1 – Shahriar

+0

Avez-vous déclarer le doc Html comme "HtmlAgilityPack.HtmlDocument" et pas simplement comme "HtmlDocument"? – Graffito

Répondre

0

Solution 1: Installation de-paquet HtmlAgilityPack

https://www.nuget.org/packages/HtmlAgilityPack/

Solution 2: analyse syntaxique HTML

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[^]