Hi all,

How can I retrieve info from a HTML table like this :
I want the bold things.

<table class="vis "> 
	<tr> 
		[B]<th width="150">Opslagplaats vol</th> 
		<th>Tijd (hh:mm:ss)</th> [/B]
	</tr> 
 
						<tr> 
				[B]<td width="250"><img src="graphic/holz.png?1" title="Hout" alt="" class=""/> morgen om 02:35:48 uur</td> [/B]
				<td> 
					<span class="timer">8:32:33</span> 
				</td> 
			</tr> 
								<tr> 
				[B]<td width="250"><img src="graphic/lehm.png?1" title="Leem" alt="" class=""/> morgen om 05:27:00 uur</td> [/B]
				<td> 
[B]					<span class="timer">11:23:45</span> 
[/B]				</td> 
			</tr> 
								<tr> 
				[B]<td width="250"><img src="graphic/eisen.png?1" title="IJzer" alt="" class=""/> morgen om 06:14:38 uur</td> [/B]
				<td> 
[B]					<span class="timer">12:11:23</span> 
[/B]				</td> 
			</tr> 
			
</table> 
</td></tr>

Thanks,

Vhyr

Recommended Answers

All 4 Replies

What bold things?

If you want to extract information from a HTML source, then the easiest solution would be to read the entire content into string using a StreamReader.
Once that is done, you can use string functions, like IndexOf and SubString, to locate and extract the information.

In other words, you will have to parse the source "manually".

How would I extract it from the source?

Like so:

Imports System
Imports System.IO
Imports System.Net

Private Function FetchSource() As String
   'Address of URL
   Dim URL As String = "http://www.somesite.com/somepage.html"

   'Create a WebRequest object, used to send the request to the website
   Dim request As WebRequest = WebRequest.Create(URL)

   'Create a WebResponse object, used to contain the response from the website
   Dim response As WebResponse = request.GetResponse()

   'Create a StreamReader object, used to read the incoming data from the website
   Dim reader As StreamReader = New StreamReader(response.GetResponseStream())

   'Read the entire content from the StreamReader object into a string variable
   Dim str As String = reader.ReadToEnd()
   reader.Close()

   Return str
End Function

And once you have the source, ie the HTML code, you can use standard string functions to locate and extract the information.

Private Sub ParseSource()
   Dim src As String = FetchSource()
   Dim temp As String
   Dim index As Integer

   'Locate the initial tag in the source
   index = src.IndexOf("<sometag>")
   If index > 0 Then
      'Extract everything from the source beginning from the located index
      temp = src.SubString(index)
      'Locate the next index in order to narrow it down
      index = temp.IndexOf("</sometag>")
      temp = temp.SubString(0, index)
      
      'temp should now contain only the information found within a certain specific tag
   End If
End Sub

With a new slight modifications to the code by adding a few more IndexOf and SubString, you can easily locate and extract anything you whish to find.

Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.