HtmlAgilityPack and windows 8 winRT

﹥>﹥吖頭↗ 提交于 2020-02-07 04:07:40

问题


I'm trying to build a metro app for windows 8. In this app i'm trying to parse data from a website. For that i'm using HtmlAgilityPack 1.4.6. BUT i'm getting really confused about 'Dose HAP 1.4.6 works with windows 8?' and 'Dose it support Xpath?' Too much confusing info on Codeplex. As for now it seems that it works on windows 8 BUT i can't see HtmlNode.SelectNode method. If Xpath is not working, is there any other option to do the parsing? Can you direct me to a tutorial or examples? please...

Yours


回答1:


You can use the LINQ API:

var doc = new HtmlDocument();
doc.LoadHtml(contents);
var programmes = doc.DocumentNode.Descendants().Where(d => d.GetAttributeValue("class", "") == "program")

Unfortunately, I couldn't find much up-to-date information on this API.




回答2:


I was created few weeks ago my own algorithm to save web page and I also solved problem for parsing html code for img css js in windows 8 metro-app with help of these few lines:(for all images, in HtmlDocument html, links example)

IEnumerable<HtmlNode> imghrefNodes = html.DocumentNode.Descendants().Where(n => n.Name == "img");
foreach (HtmlNode img in imghrefNodes)
{
   HtmlAttribute att = img.Attributes["src"];
   //in att.Value you can find your img url
   //Here you can do everything what you want with all img links by editing att.Value
}

For css you can just replace img with link and src with href. For other nodes the same way.



来源:https://stackoverflow.com/questions/12829137/htmlagilitypack-and-windows-8-winrt

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