Reputation: 551
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!
Upvotes: 0
Views: 840
Reputation: 101
You need to add the library(HTMLAgilityPack) to your references and then use the 'using' keyword in the top of your file to use it.
Upvotes: 1