请帮助我解决这个问题:
private void DownLoadCompleted(object sender, HtmlDocumentLoadCompleted e)
{
var doc = new HtmlDocument();
doc.LoadHtml("http://www.unnu.com/popular-music-videos");
//var query = doc.DocumentNode.Descendants("img");
MessageBox.Show("chegou");
foreach (HtmlNode linkNode in doc.DocumentNode.SelectNodes("@//img[@src]"))
{
HtmlAttribute link = linkNode.Attributes[@"href"];
HtmlNode imageNode = linkNode.SelectSingleNode(@"//.php?src");
HtmlAttribute src = imageNode.Attributes[@"src"];
string Link = link.Value;
Uri imageUrl = new Uri(src.Value);
MessageBox.Show("chegou");
}
}
我需要使用您各自的网址获取所有图片和标题。我正在使用Windows Phone 7.5。 dll是一样的。
答案 0 :(得分:0)
doc.LoadHtml
需要 html ,而不是网址。你在寻找这样的东西吗?
var web = new HtmlAgilityPack.HtmlWeb();
var doc = web.Load("http://www.unnu.com/popular-music-videos");
var imgs = doc.DocumentNode.SelectNodes(@"//img[@src]")
.Select(img => new
{
Link = img.Attributes["src"].Value,
Title = img.Attributes["alt"].Value
})
.ToList();
如果HtmlAgilityPack的WP7版本不支持 HtmlWeb ,您也可以使用 WebClient 获取html字符串,它可以用作doc.LoadHtml
的参数< / p>