c# HtmlAgilityPack Wrapp taking several images, titles and links Windows Phone [closed]

前提是你 提交于 2019-12-13 09:14:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!