问题
How to fetch the data on this page? I need to get the image and its corresponding title and display in a list box. Using class or not. I do not know how to do, please help me!
Do not even know where to start! I've tried several things and none work, then turned into a mess, would someone guide me from the beginning.
var imgs = e.Document.DocumentNode.SelectNodes(@"//img[@src]")
.Select(img => new
{
Link = img.Attributes["src"].Value,
Title = img.Attributes["alt"].Value,
}).ToList();
listBoxPopular.ItemsSource = imgs;
foreach (var item in imgs)
{
listBoxPopular.Items.Add(new PopularVideos(item.Title, item.Link));
}
回答1:
var data = doc.DocumentNode.SelectSingleNode("//div[@class='content']")
.Descendants("img")
.Select(img => new
{
Title = img.Attributes["alt"].Value,
Url = img.Attributes["src"].Value,
})
.ToList();
来源:https://stackoverflow.com/questions/17476917/c-sharp-htmlagilitypack-wrapp-taking-several-images-titles-and-links-windows-ph