How to get data from html source in visual basic as string
trying to read the customer number from there into a string
<TD width="45%" valign=center align=right class=HeaderLabel2>John Doe(123456789) []</TD>
here is also the problem that if youve get the value of Headerlabel2 it must be split up like name, forename, costumerid...
buttoncontrol and fill in form that i can but i cant find a way to read the costumer number in a string in visual basic 2010
someone knows the code?
thinking of some kind code like this but cant find it
Try
Dim username As String
Dim password As String
techid = My.Settings.username
techpass = My.Settings.password
browser.Document.GetElementById("username_5").InnerText = username
browser.Document.GetElementById("password_5").InnerText = password
browser.Document.GetElementById("btnsubmit_6").InvokeMember("Click")
Catch ex As Exception
End Try
Re: How to get data from html source in visual basic as string
i need to get the source code out of the webpage into vb so i can split it up in multiple strings.
Re: How to get data from html source in visual basic as string
Re: How to get data from html source in visual basic as string
vb.net Code:
Dim splitted() As String = Split(SOURCE_STRING, "HeaderLabel2>")
Dim data As String = Trim(Split(splitted(1), "<")(0))
Dim split_data() As String = Split(data, " ")
Dim Forename As String = split_data(0)
Dim Name As String = split_data(1)
'clean customer
Dim temp_customer As String = Split(Trim(split_data(2)), ")")(0)
Dim Customer_ID As String = temp_customer.Substring(1)
MsgBox(Forename & vbCrLf & Name & vbCrLf & Customer_ID)
Re: How to get data from html source in visual basic as string
Quote:
Originally Posted by
ShadowTzu
vb.net Code:
Dim splitted() As String = Split(SOURCE_STRING, "HeaderLabel2>")
Dim data As String = Trim(Split(splitted(1), "<")(0))
Dim split_data() As String = Split(data, " ")
Dim Forename As String = split_data(0)
Dim Name As String = split_data(1)
'clean customer
Dim temp_customer As String = Split(Trim(split_data(2)), ")")(0)
Dim Customer_ID As String = temp_customer.Substring(1)
MsgBox(Forename & vbCrLf & Name & vbCrLf & Customer_ID)
can you please explaine the code a bit because i tried copy paste the code but it doesnt work
got a error on Dim data As String = Trim(Split(splitted(1), "<")(0))
index was inside the bounds of the array...
thx in advanced
Re: How to get data from html source in visual basic as string
vb.net Code:
'you need to replace SOURCE_STRING by the source code of your webpage example: Dim splitted() As String = Split(GetCurrentWebDoc.documentElement.outerHTML, "HeaderLabel2>")
Dim splitted() As String = Split(SOURCE_STRING, "HeaderLabel2>")
'from here splitted is an array of string with two entry: splitted(0) = every text found before "HeaderLabel2>" and splitted(1) = every text found after "HeaderLabel2>"
'if Split doesn't found "HeaderLabel2>" then splitted contain only one entry: splitted(0) = GetCurrentWebDoc.documentElement.outerHTML -> The following code will not work.
'you can add a new line to check that:
If splitted.Count = 1 then
MsgBox ("Data can't be found!")
Return
end If
'From here splitted contain: splitted(1) = "Deceuninck Rik (645956140) [Mediors]</TD> <!-- DESIGN END ADD HEADERJSP:ICS_WFM--> ...........(and the rest of the source)"
'We need to get every text before the first "<"
Dim data As String = Trim(Split(splitted(1), "<")(0))
'result: data = "Deceuninck Rik (645956140) [Mediors]"
'Split again with space char:
Dim split_data() As String = Split(data, " ")
'result: split_data(0) and split_data(1) contain what you need and split_data(2) need to be cleaned a little
Dim Forename As String = split_data(0)
Dim Name As String = split_data(1)
'clean customer because split_data(2) = "(645956140) [Mediors]"
Dim temp_customer As String = Split(Trim(split_data(2)), ")")(0)
Dim Customer_ID As String = temp_customer.Substring(1)
MsgBox(Forename & vbCrLf & Name & vbCrLf & Customer_ID)
Re: How to get data from html source in visual basic as string
ShadowTzu i assume you come from a vb6 background? Loads of legacy code there.
Re: How to get data from html source in visual basic as string
So if i follow your structure a bit and clean up the code a bit :-) i came to this "solution"
Dim splitted() As String = Split(SOURCE, "align=right>")
SOURCE = splitted(1)
txtinput.Text = SOURCE
Dim data() As String = Split(SOURCE, " ")
SOURCE = data(0)
txtinput.Text = SOURCE
this gives the result
Deceuninck Rik (645956140)
then i can resplit on the space so that
split(0) = name
split(1) = forename
split(2) = costumer number
but if the value of source is more like 1 name it splits wrong...
example
van den berghe john (123456789)
then it splits wrong
split(0) = van
split(1) = den
split(2) = berghe
so this gives a false value
what im now trying to do is find the numeric string and import it as costumer number but didnt find a solution jet to split the name and forname properly :-)
thx in advanced
Blackeagle8100
Re: How to get data from html source in visual basic as string
txtinput.Text = ""
klantennummer = ""
ShowPageSource()
Dim splitted() As String = Split(SOURCE, "align=right>")
SOURCE = splitted(1)
txtinput.Text = SOURCE
Dim data() As String = Split(SOURCE, " ")
SOURCE = data(0)
Dim myChars() As Char = SOURCE.ToCharArray()
For Each ch As Char In myChars
If Char.IsDigit(ch) Then
klantennummer = klantennummer & ch
End If
Next