简体   繁体   中英

Issue with HtmlDocument and WP8

I am trying to understand how HTMLAgilityPack actually works, I found a guide on this website, http://www.tareqateik.com/html-agility-pack%E2%80%93windows-phone-8#.Uw-TcbG8_q4

I have an issue with HtmlDocument, since Visual Studio 2013 reports an error: "The type or namespace name 'HtmlDocument' could not be found (are you missing a using directive or an assembly reference?)"

This is the full code I am working on, at the moment:

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


    }
}

Thanks in advance!

您需要将库(HTMLAgilityPack)添加到引用中,然后在文件顶部使用'using'关键字来使用它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM