Results 1 to 20 of 20

Thread: [RESOLVED] Read number from website

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    Resolved [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

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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

  4. #4
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    Smile 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!
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    Re: Read number from website

    Hey this is great,

    I have modified it a bit to this:
    VB Code:
    1. Dim strNumbers() As String
    2.         Dim seps(0) As String
    3.         Dim intX As Integer
    4.  
    5.         seps(0) = "</a>&nbsp;&nbsp;</font></td>"
    6.         strNumbers = strSource.Split(seps, StringSplitOptions.None)
    7.         For intX = 0 To UBound(strNumbers)
    8.             strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
    9.             rtbResult.Text = rtbResult.Text & vbCrLf & strNumbers(intX)
    10.         Next
    11.     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:
    1. seps(0) = "part of code" this is the number "part of code"

    Thanks alot so far

    Sam

  6. #6
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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:
    1. strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
    What would happen to the number at the end?

    Sam

  8. #8
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    Re: Read number from website

    Ok thanks alot looking forward to it, thanks for your help so far.

    Sam

  10. #10
    Member
    Join Date
    May 2006
    Posts
    61

    Re: Read number from website

    Wouldn't a regular expression be easier?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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:
    1. Dim strNumbers() As String
    2.         Dim seps(1) As String
    3.         Dim intX As Integer
    4.         seps(1) = "</a>&nbsp;&nbsp;</font></td>"
    5.         seps(0) = "/d/USD/GBP/graph120.html" & Chr(34) & "class=" & Chr(34) & "menu" & Chr(34) & ">"
    6.  
    7.         'say the code was: class="bactive" title
    8.         '"class=" & chr(34) & "bactive" & chr(34) & " title"
    9.  
    10.         strNumbers = strSource.Split(seps, StringSplitOptions.None)
    11.         For intX = 0 To UBound(strNumbers)
    12.             strNumbers(intX) = strNumbers(intX).Substring(Len(strNumbers(intX)) - 10)
    13.             rtbResult.Text = rtbResult.Text & vbCrLf & strNumbers(intX)
    14.         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>&nbsp;&nbsp;</font></td>
    Have you updated your end yet? I have no idea.

    Sam

  12. #12
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  13. #13
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  14. #14
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...
    Attached Files Attached Files

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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:
    1. seps(0) = "/d/GBP/USD/graph120.html" & Chr(34) & " class=" & Chr(34) & "menu" & Chr(34) & ">"
    2.         seps(1) = "</a>&nbsp;&nbsp;</font></td>"
    Also I am will post my currency converter when I am done.
    Sam

  17. #17
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    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...

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    208

    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
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width