我设法解析了来自newssite(ryfylke.net)的HTML(内容)并将其显示在我的WP8应用程序中。但是,我如何解析子页面中的内容(“阅读更多”链接)? 现在,当我点击链接时,应用程序启动IE并显示实际站点。但我想要做的是解析网站上的内容并将其显示在应用程序中。
编辑(这是我目前的MainPage.xaml.cs)
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string htmlPage = "";
using (var client = new HttpClient())
{
htmlPage = await client.GetStringAsync("http://ryfylke.net/kategori/nyheter/");
}
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(htmlPage);
List<Nyheter> nyheter = new List<Nyheter>();
foreach (var div in htmlDocument.DocumentNode.SelectNodes("//article[starts-with(@class, 'post-')]"))
{
Nyheter newNyheter = new Nyheter();
newNyheter.Link = div.SelectSingleNode(".//a[@href]").Attributes["href"].Value;
newNyheter.Bilde = div.SelectSingleNode(".//img[@class='attachment-entry-medium wp-post-image']").Attributes["src"].Value;
newNyheter.Tittel = div.SelectSingleNode(".//h2[@class='entry-title entry-small-title']").InnerText.Trim();
newNyheter.Sammendrag = div.SelectSingleNode(".//p[@class='entry-excerpt']").InnerText.Trim();
nyheter.Add(newNyheter);
}
lstNyheter.ItemsSource = nyheter;
}
然后我使用这样的公共字符串来使用内容......
public string Bilde { get; set; }