Solved

Htmlagilitypack -> Selecting columns from tables

Posted on 2014-02-19
1
1,665 Views
Last Modified: 2014-03-07
Hi all,

I am looking to select 3 colums from every table within the webpage that has a specific id...

im using the following code to do this

Imports System.IO
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports HtmlAgilityPack
Partial Class Grayhounds_home
    Inherits System.Web.UI.Page
    '  Gettodaysmatches(cominguptable, "https://www.betfair.com/sport/football?selectedTabType=TODAY", ".//div[contains(@class, 'match event-information ui-event')]", ".//span[@class='home-team-name']", ".//span[@class='away-team-name']", ".//span[@class='ui-no-score']")

    Private Sub Grayhounds_home_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim webGet As New HtmlWeb() 'open the system
        Dim doc As HtmlDocument = webGet.Load("http://www.greyhoundpredictions.co.uk/results.php") '' get the html from the webpage

        Dim tables As HtmlNodeCollection = doc.DocumentNode.SelectNodes(".//table[@id='inner']")
        Dim rows As HtmlNodeCollection = tables(0).selectNodes(".//tr")

        Dim makeSpace As String = vbLf & vbLf

        For i As Integer = 1 To rows.Count - 1
            Dim cols As HtmlNodeCollection = rows(i).SelectNodes(".//td")

            Dim Pred As String = cols(0).InnerText
            Dim Act As String = cols(1).InnerText
            Dim Odds As String = cols(4).InnerText


            Console.WriteLine("Pred : " & Pred & vbLf)
            Console.WriteLine("actual : " & Act & vbLf)
            Console.WriteLine("Odds : " & Odds & vbLf)

            Console.WriteLine(makeSpace)
        Next

    End Sub
End Class

Open in new window



The thing is im getting nothing returned?????

here is the snippit of the table html
<table id="inner" border="1" width="25"><h3>20:25 07/02/2014
 S3
</h3><th>Pred</th><th>Act</th><th>Name</th><th>Age</th><th>Odds</th><tr><td>1 (44.8)</td><td>2</td><td align ="center" width="8">Grandads Rifle</td><td>50</td><td>6/4F</td></tr>
<tr><td>2 (39.1)</td><td>3</td><td align ="center" width="8">Rosario Girl</td><td>33</td><td>3/1</td></tr>
<tr><td><b>3 (38.6)</b></td><td><b>1</b></td><td align ="center" width="8"><b>Zulu Hondo</b></td><td><b>33</b></td><td><b>6/1</b></td></tr>
<tr><td>4 (37.6)</td><td>6</td><td align ="center" width="8">Lethal Tiger</td><td>53</td><td>9/4</td></tr>
<tr><td>5 (33.4)</td><td>4</td><td align ="center" width="8">Redstone Bo Dhu</td><td>33</td><td>6/1</td></tr>
<tr><td>6 (27.8)</td><td>5</td><td align ="center" width="8">Corgrigg Candy</td><td>25</td><td>8/1</td></tr>
</table id="inner">

Open in new window


can anyone figure out why im getting no results?
0
Comment
Question by:runnerjp2005
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
I ran this code against that URL, and I got 542 tables.

   Dim webGet As New HtmlWeb()

        ' Get the html from the webpage
        Dim doc As HtmlDocument = webGet.Load("http://www.greyhoundpredictions.co.uk/results.php")
        
        Dim tables As HtmlNodeCollection = doc.DocumentNode.SelectNodes(".//table[@id='inner']")
        Dim rows As HtmlNodeCollection = tables(0).SelectNodes("tr")

        For Each row As HtmlNode In rows
            Dim cols As HtmlNodeCollection = row.SelectNodes("td")

            Dim pred As String = cols(0).InnerText
            Dim act As String = cols(1).InnerText
            Dim odds As String = cols(4).InnerText

            Console.WriteLine("Pred : " & pred & vbLf)
            Console.WriteLine("actual : " & act & vbLf)
            Console.WriteLine("Odds : " & odds & vbLf)

            Console.WriteLine(vbLf & vbLf)
        Next

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now