Question

the awesomium answering forums seem pretty much dead, so I'm reposting this here

First of all, before starting to learn Awesomium I used the HtmlAgilityPack library for all my parsing needs, but the library is not being updated anymore and I decided to move to Awesomium. (so my approach is based on my experience with HAP)

I figured out how to parse lists of objects with Awesomium, but I can't figure out how to work with them. For example:

     public dynamic FindNodes(string xpath, dynamic node = null, WebView wv = null)
            {
                if (wv == null) wv = mainView;
                dynamic nodes = (JSObject)wv.ExecuteJavascriptWithResult(String.Format("document.evaluate(\"{0}\", {1}, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)", xpath, "document")));
                int length = nodes.snapshotLength;
                for (int i = 0; i < length; i++)
                {
                    Console.WriteLine(nodes.snapshotItem(i).innerText);
                }
                return nodes;
            }

The problems start after I return the nodes. I want to perform a series of searches for each node, so after returning them I decided that the following should work:

dynamic weakCounters = ap.FindNodes("//div[@id='weaklist']/ul/li");
            for (int i = 0; i < weakCounters.snapshotLength; i++)
            {
                ap.FindNodes("//h3[@class='black']", weakCounters.snapshotItem(i));
            }

But it did not. The part where I'm trying to get the length of the list and of course, if I try to get a snapshot of the item directly I get an error.

I understand, that I'm making a HUGE mistake somewhere. I just can't understand where.

Edit: Surprisingly if I do the following, everything seems fine, but it just doesn't look right to create a new variable everytime I need to access it (that's just bananas)

dynamic weakCounters = ap.FindNodes("//div[@id='weaklist']/ul/li");
            dynamic nodes = weakCounters;
            for (int i = 0; i < nodes.snapshotLength; i++)
            {

Also, how can I pass the result (element) that I have extracted back to awesomium so that I could do a "subsearch" ?

Was it helpful?

Solution

cross-posted answer from http://answers.awesomium.com/questions/4276/parsing-with-awesomium.html

Why do you need Awesomium for HTML parsing? What's wrong with HtmlAgilityPack?

Download page with Awesomium (if that is why you need it), get HTML, parse it with HtmlAgilityPack.

Parsing like this should be very slow (if it return many elements).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top