Hello everyone,
what i am trying todo is get the following data from a html file....
Friday 31 - 1 - 2014
Created: 31/01/2014 2:32 PM
Updated: 31/01/2014 7:03 PM
Location: 37°35'13 S 145°7'41 E
Shift 143
Car 7008
Bus 280
564 / 9
Car 7008
Car 7011
Bus 361
572 / 20
the html file looks like this...
<html>
<head>
<title>Evernote Export</title>
<basefont face="Tahoma" size="2" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="exporter-version" content="Evernote Windows/276152; Windows/6.3.9600;"/>
<style>
body, td {
font-family: Tahoma;
font-size: 10pt;
}
</style>
</head>
<body>
<a name="655"/>
<h1>Friday 31 - 1 - 2014</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>Created:</b></td><td><i>31/01/2014 2:32 PM</i></td></tr>
<tr><td><b>Updated:</b></td><td><i>31/01/2014 7:03 PM</i></td></tr>
<tr><td><b>Location:</b></td><td><a href="http://maps.google.com/maps?z=6&q=-37.587000,145.128000"><i>37°35'13 S 145°7'41 E</i></a></td></tr>
</table>
</div>
<br/>
<div><span style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Shift 143<br/>Car 7008<br/>Bus 280<br/>564 / 9<br/>Car 7008<br/>Car 7011<br/>Bus 361<br/>572 / 20<br/></div></span>
</div></body></html>
my code looks like this at the moment...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists("H:\michael-documents\friday31.html") Then
Dim str As String = My.Computer.FileSystem.ReadAllText("H:\michael-documents\friday31.html")
' search string for Required Data
Dim Findstr As String
'The number you get below is the START
Findstr = (str.IndexOf("<h1>"))
Dim Findstr2 As String
'The number you get below is the START
Findstr2 = (str.IndexOf("</h1>"))
Dim Findstr3 As String
'This get the Characters needed.
Findstr3 = (str.Substring(Findstr + 4, ((Findstr2 - 4) - Findstr)))
Dim Bstr As String
'This finds the Date & Time file was Created
Bstr = (str.IndexOf("<b>"))
Dim Bstr2 As String
Bstr2 = (str.IndexOf("</b>"))
Dim Bstr3 As String
Bstr3 = (str.Substring(Bstr + 3, ((Bstr2 - 4) - Bstr)))
Dim istr As String
istr = (str.IndexOf("<i>"))
Dim istr2 As String
istr2 = (str.IndexOf("</i>"))
Dim istr3 As String
istr3 = (str.Substring(istr + 3, ((istr2 - 3) - istr)))
Dim Createdstr As String
Createdstr = (Bstr3 + " " + istr3)
Dim B1str As String
B1str = (str.IndexOf("Updated"))
Dim B1str3 As String
B1str3 = (str.Substring(B1str, 8))
Dim B1str4 As String
B1str4 = (str.Substring(B1str + 24, 18))
Dim Updatedstr As String
Updatedstr = (B1str3 + " " + B1str4)
Dim Locstr As String
Locstr = (str.IndexOf("Location"))
Dim Locstr2 As String
Locstr2 = (str.Substring(Locstr, 8))
Dim Locstr3 As String
Locstr3 = (str.IndexOf("<i>37"))
Dim Locstr4 As String
Locstr4 = (str.Substring((Locstr3 + 3), 22))
Dim Locationstr As String
Locationstr = (Locstr2 + " " + Locstr4)
TextBox1.Text = Locstr3
TextBox2.Text = Locstr4
ListBox1.Items.Add(Findstr3)
ListBox1.Items.Add(Createdstr)
ListBox1.Items.Add(Updatedstr)
ListBox1.Items.Add(Locationstr)
Else
MsgBox("File not found.")
End If
End Sub
I think there has to be a better/simple way of doing this...
Thanks for reading.