Pulling HTML Information using VB.Net and Webbrowser

sodacycle

Distinguished
Mar 18, 2011
6
0
18,510
First off let me state that this isn't any kind of homework, I've been programming with VB.net since January on my own time.

The purpose of the application:

I'm trying to make a custom webbrowser for the browser game Travian,following their TOS, I'm only going to show information that is available to all players regardless of if they use "Gold" or not. I do not want to mess with/ inject any scripts (like greasemonkey uses) into the browser to get the information because Travian's TOS states that scripts that do this are forbidden.

My problem:

I'm trying to pull some information from the webpage using the webbroswer in Visual Basic, but the information I want to pull looks like this in HTML;

Code:
<div class="boxes-contents cf"><table id="production" cellpadding="1" cellspacing="1">
	<thead>
		<tr>
			<th colspan="4">
				Production per hour:			</th>
		</tr>
	</thead>
	<tbody>
				<tr>
			<td class="ico">
				<img class="r1" src="img/x.gif" alt="Wood" title="Wood" />
			</td>
			<td class="res">
				Wood:
			</td>
			<td class="num">
				1320			</td>
		</tr>
				<tr>
			<td class="ico">
				<img class="r2" src="img/x.gif" alt="Clay" title="Clay" />
			</td>
			<td class="res">
				Clay:
			</td>
			<td class="num">
				1401			</td>
		</tr>
				<tr>
			<td class="ico">
				<img class="r3" src="img/x.gif" alt="Iron" title="Iron" />
			</td>
			<td class="res">
				Iron:
			</td>
			<td class="num">
				1230			</td>
		</tr>
				<tr>
			<td class="ico">
				<img class="r4" src="img/x.gif" alt="Wheat" title="Wheat" />
			</td>
			<td class="res">
				Wheat:
			</td>
			<td class="num">
				1112			</td>
		</tr>
			</tbody>
</table>
	</div>

I've pulled other information, such as village name and resource information like this;

*NOTE* This is inside a Timer so it will refresh the information ever 2ms just like the website does, There's no catch because you have to login to the site and the try statement simply keeps it from crashing while you login.

Code:
Try
                GroupBox3.Text = WebBrowser1.Document.All.Item("villageNameField").InnerHtml()
                lblWood.Text = WebBrowser1.Document.All.Item("l1").InnerHtml()
                lblClay.Text = WebBrowser1.Document.All.Item("l2").InnerHtml()
                lblIron.Text = WebBrowser1.Document.All.Item("l3").InnerHtml()
                lblWheat.Text = WebBrowser1.Document.All.Item("l4").InnerHtml()
            Catch

            End Try

I've tried using the same technique to get the production information but because they all use "num" and "res" it didn't work. I've never done anything like this in VB before and any advice/help is greatly appreciated.

The question:

How can I pull the production information in the same way I did the resource information if the id's are the same for all of the production classes?

 

majestic1805

Honorable
Oct 1, 2012
69
0
10,590
First, unless you're using Windows 8 it's not going to happen every 2 ms. It's going to happen at some multiple of 15.6. This is how the kernel works Win 7 and back.

Second, I'd suggest using the HttpWebRequest/Response objects and use a regular expression to scrape the number you're looking for.