[英]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.