简体   繁体   中英

How do I use HtmlAgilityPack on Windows Phone 8.1?

I've made a quick C#/Mono prototype of an app I want to build for Windows Phone 8.1, using HtmlAgilityPack.

Converting this code to WP8.1 and official .Net for Windows Store is turning out to be troublesome. All I want is a to fetch all of the td nodes with a class attibute of "column3". How would I do this? Things work fine using SelectNodes for my non-store prototype.

Now I understand that for Windows Store apps, SelectNodes and SelectSingleNode are missing. My problem, however is that the suggested alternatives of using linq and Decendants do not work either.

I've googled around of course, but for some reason all of the results include one of the below, or variations of them.

What I've tried so far:

var hits = doc.DocumentNode.SelectNodes("//td[@class=\"column3\"]");
//SelectNodes is undefined

var hits = doc.DocumentNode.DescendantsAndSelf("td").Where(x => x.Name.ToLower() =="td"); 
//Where() is undefined

HtmlNode parent = doc.DocumentNode
                      .Descendants("ul")
                      .FirstOrDefault(o => o.GetAttributeValue("class", "") 
                                               == "songs-list1");
//doesn't do what i want it to, but FirstOfDefault is undefined

I suspect you missed the required using statement. The following should return all <td> nodes having attribute class equals "column3" :

using System.Linq;
.......
var hits = doc.DocumentNode
              .Descendants("td")
              .Where(o => o.GetAttributeValue("class", "") 
                                    == "column3")
              .ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM