如何将此代码转换为UWP方式? [英] How to convert this code to UWP way?

查看:90
本文介绍了如何将此代码转换为UWP方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

im学习编写UWP,但我学到的很多东西都不能用了?

你能帮助我吗?



Hi guys ,
i m lerning to coding UWP,but a lot of things i learnt doesnt work anymore?
could u guys help me?

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 }))





编译器说它找不到 的类或命名空间Webclient

i也尝试了Httpclient,但它仍然可以工作。

Thanx!



我尝试了什么:



i也尝试了Httpclient,但它仍然可以正常工作。



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.

推荐答案

解决方案1:安装包HtmlAgilityPack



[ Nuget package Link ]



解决方案2:解析HTML



Solution 1: Install-Package HtmlAgilityPack

[ Nuget package Link ]

Solution 2: Parsing 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使用C#中的C#示例解析Html,用于Visual Studio 2013 [ ^ ]


这篇关于如何将此代码转换为UWP方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆