簡體   English   中英

HtmlDocument和WP8的問題

[英]Issue with HtmlDocument and WP8

我試圖了解HTMLAgilityPack的實際工作原理,我在此網站上找到了一個指南, 網址為http://www.tareqateik.com/html-agility-pack%E2%80%93windows-phone-8#.Uw-TcbG8_q4

我遇到了HtmlDocument的問題,因為Visual Studio 2013報告了一個錯誤:“找不到類型或名稱空間名稱'HtmlDocument'(您是否缺少using指令或程序集引用?)”

這是我目前正在處理的完整代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using FedoraCoin.Resources;
using System.Net.Http;
using System.Windows.Controls.

namespace FedoraCoin
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string htmlPage = "";
            using (var client = new HttpClient())
            {
                htmlPage = await client.GetStringAsync("http://www.imdb.com/movies-in-theaters/");
            }

            HTMLDocument htmlDocument = new HtmlDocument();
            htmlDocument.LoadHtml(htmlPage);

            List<Movie> movies = new List<Movie>();
            foreach (var div in htmlDocument.DocumentNode.SelectNodes("//div[starts-with(@class, 'list_item')]"))
            {
                Movie newMovie = new Movie();
                newMovie.Cover = div.SelectSingleNode(".//div[@class='image']//img").Attributes["src"].Value;
                newMovie.Title = div.SelectSingleNode(".//h4[@itemprop='name']").InnerText.Trim();
                newMovie.Summary = div.SelectSingleNode(".//div[@class='outline']").InnerText.Trim();
                movies.Add(newMovie);
            }
            lstMovies.ItemsSource = movies;
        }


    }
}

提前致謝!

您需要將庫(HTMLAgilityPack)添加到引用中,然后在文件頂部使用'using'關鍵字來使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM