[RESOLVED] Read number from website
Hi all
I wondered if anyone could tell me if it is possible to read a number from a website and then save it in my app as a setting. Then when a update button is click it goes back to the website and gets then updated number. This would probably be the site http://www.x-rates.com/ I would want to take one of the numbers in the currency table. Can this be done? If so, Can someone show me how?
Thanks
Sam
Re: Read number from website
Its simple yo... use an Internet Transfer Control to get the source then use string.split to split into ways such that u can extract out the number such as the class="bactive" delimeters...
Re: Read number from website
I have no idea what that means I am quite a noob. Could you do an example where it takes one of the numbers in that table and puts them in a textbox, it would be a great help.
Sam
1 Attachment(s)
Re: Read number from website
Hey here you go... this is a very basic example. You can basically take anything you want from a website using its source. But remember it would HAVE to be different for different websites. Let me know if this helps!
Re: Read number from website
Hey this is great,
I have modified it a bit to this:
VB Code:
Dim strNumbers() As String
Dim seps(0) As String
Dim intX As Integer
seps(0) = "</a> </font></td>"
strNumbers = strSource.Split(seps, StringSplitOptions.None)
For intX = 0 To UBound(strNumbers)
strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
rtbResult.Text = rtbResult.Text & vbCrLf & strNumbers(intX)
Next
End Sub
This takes it from the other table, but these numbers are not the same length as each other. So some take some of the other code and some are not complete.
What I would like to is take the number between to bits of code, so this would also mean that I would be able to choose which of the numbers I want. Its ok me saying this but I do not know how to do it.
I suppose this code would be something like this not sure at all though:
VB Code:
seps(0) = "part of code" this is the number "part of code"
Thanks alot so far
Sam
Re: Read number from website
hey i think you should try this...
seps(0) = "part of code before number"
seps(1) = "part of code after number"
This way it will be included in the strNumbers array...
Re: Read number from website
Ok I have tried to do this but I have no idea what I am doing and how to get it working. Could you try to get it working with you first example and post it again?
The problems I am having is the html has "" in it which tricky, because I want to go all the way back to where it says what the number is for e.g
Code:
"/d/USD/GBP/graph120.html" class="menu">
This means I am able to take the numbers I actually want.
Another problem is that this part:
VB Code:
strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
What would happen to the number at the end?
Sam
Re: Read number from website
Hey I am not sure what u are saying on your last post but if the code part had quotes then u can do this:
say the code was: class="bactive" title
you can do "class=" & chr(34) & "bactive" & chr(34) & " title"
And i'll post the code for getting the other number on tuesday. What my code currently does is that it saves the source code in strSource. Then seps is the array of string which act as the seperator. Eg: blah ="1 2,3-4" would be seperated into any array str(0) = 1 str(1) = 2... if the sep(0) = " " and seps(1) = "," and seps(2) = "-"... when blah.split(seps) is called... So once you hit GO, you just need to figure out how u can seperate what u want from the rest of the code.
Just clarify a little more and i'll update the program soon...
Re: Read number from website
Ok thanks alot looking forward to it, thanks for your help so far.
Sam
Re: Read number from website
Wouldn't a regular expression be easier?
Re: Read number from website
Hi
I have been trying to do this for days, still cant get it to work, this is the kind of thing I have been using:
VB Code:
Dim strNumbers() As String
Dim seps(1) As String
Dim intX As Integer
seps(1) = "</a> </font></td>"
seps(0) = "/d/USD/GBP/graph120.html" & Chr(34) & "class=" & Chr(34) & "menu" & Chr(34) & ">"
'say the code was: class="bactive" title
'"class=" & chr(34) & "bactive" & chr(34) & " title"
strNumbers = strSource.Split(seps, StringSplitOptions.None)
For intX = 0 To UBound(strNumbers)
strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
rtbResult.Text = rtbResult.Text & vbCrLf & strNumbers(intX)
Next
This still just give the 10 characters before the seps(1). I have this without the - 10 still no joy.
The number I want is:
HTML Code:
="/d/USD/GBP/graph120.html" class="menu">1.93849</a> </font></td>
Have you updated your end yet? I have no idea.
Sam
Re: Read number from website
Hey tell me eactly which rates do u want to extract from the xrates website... are u talking about the table on the bottom or the top? i did the top one... im gonna do the bottom on and will post it today... hopefully in like 30 mins...
Re: Read number from website
I think ur code doesnt work because u need a space between class in ur seps... hold on making my program right now will post in like 15 mins...
1 Attachment(s)
Re: Read number from website
ok done... i used a little trick to seperate the numbers here... look at my seps they are before and after... and then only picks ones that are small... let me know if u get it? cuz understanding the concept is more important here than the program if you also wanna use the idea with other websites...
Re: Read number from website
Ok thanks just about to look at it on, my laptop at the moment which doesn't have vb.
Get back to you in a minute.
Sam
Re: Read number from website
Just looked at it great works perfectly, I modified a tad so I could choose which exchange rate I wanted. This is what I did:
VB Code:
seps(0) = "/d/GBP/USD/graph120.html" & Chr(34) & " class=" & Chr(34) & "menu" & Chr(34) & ">"
seps(1) = "</a> </font></td>"
Also I am will post my currency converter when I am done.
Sam
Re: Read number from website
Alright cool yo... glad I could help... I am still new to all this too... trying to learn mySQL/ASP.NET (confusing ar h3ll right now).... btw if u need my help u can contact me thru messenger usually online...
Re: Read number from website
Right been trying to put this into my existing app but having some problems, I want to do this behind the scenes to where the textbox where the source is kept is invisible also the output. But I can not get the webpage to open, it was saying like not found or something, and the source was just [html] [\html]. It think it to do with the, my app do events, I do not know what this does. Can you help?
Sam
Re: Read number from website
Also I am going to be learning some stuff with mySQL soon, if you make any projects that you think could be useful could you post them I will do the same.
Sam
1 Attachment(s)
Re: Read number from website
Here is a copy of my currency converter, not very neat at the moment but works as far as I can see.
Sam