0

I'm having issues with extracting data from the below html code, for use in a Windows Phone 8.0 Silverlight app using htmlagilitypack.

What I want to do is have the div 'game white-c' as the starting point for my node selection.

I was trying to use

foreach (var div in htmlDocumentLive.DocumentNode.SelectNodes("//div[contains(@class, 'game white-c')]"))

But this doesn't work.

Additionally, sometimes only Game3 may be available so I would need a conditional statement such as position() = 3. Other times, maybe Game1 and Game4 will be available. So I would need it to firstly check for all games. If any are unavailable i.e. contain no data, the code would then attempt to go through each game and try to load it before moving onto the next.

<section class="gamelist">
    <div class="grid">
        <div class="vc gamessection">
            <div class="col-1-4">
                <h2 class="white-c">Get free games</h2>
            </div> 
            <div class="col-3-4">
                <!-- GAME -->
                <div class="game white-c">
                    <div class="boxshot">
                    <img class="boximg" alt="Game1" src="https://images.com" title="Game1">
                    </div>
                </div>
                <!-- END GAME -->

                <!-- GAME -->
                <div class="game white-c">
                    <div class="boxshot">
                    <img class="boximg" alt="Game2" src="https://images.com" title="Game2">
                    </div>
                </div>
                <!-- END GAME -->

                <!-- GAME -->
                <div class="game white-c">
                    <div class="boxshot">
                    <img class="boximg" alt="Game3" src="https://images.com" title="Game3">
                    </div>
                </div>
                <!-- END GAME -->

                <!-- GAME -->
                <div class="game white-c">
                    <div class="boxshot">
                    <img class="boximg" alt="Game4" src="https://images.com" title="Game4">
                    </div>
                </div>
                <!-- END GAME -->

                <!-- GAME -->
                <div class="game white-c">
                    <div class="boxshot">
                    <img class="boximg" alt="Game5" src="https://images.com" title="Game5">
                    </div>
                </div>
                <!-- END GAME -->
            </div>           
        </div> 
    </div>
</section>

Thanks.

Keith K
  • 129
  • 9
  • The HTML is malformed. – Steve Wellens Jan 17 '16 at 20:21
  • The HTML is from a third party website, of which I removed excess as it wasn't needed for this purpose. However, I have edited it again. Thanks. – Keith K Jan 17 '16 at 20:54
  • @kkerswell AFAIK, HAP version for windows phone doesn't support XPath : http://stackoverflow.com/a/25262371/2998271 – har07 Jan 18 '16 at 00:50
  • @har07 Thanks, that is true of standard 8.1 Windows Phone apps. But I have been, and am using 8.0 Windows Phone Silverlight - where HAP does work. – Keith K Jan 18 '16 at 21:29

0 Answers0