Results 1 to 13 of 13

Thread: [RESOLVED] Reading from website through VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Guwahati, Assam, India
    Posts
    131

    Resolved [RESOLVED] Reading from website through VB

    Hi,

    I am developing a program that needs to read certain values from a specific website for further calculations. For example, suppose I need to read todays maximum and minimum temperatures from certain weather sites and want to report the arithmatic mean of them in a msgbox. Is it possile? If not directly, then as a workaround, if I can save the website as text file, I can read that file and find the value I want into a variable. But how to save it in the background so that the user does not see it.

    Please help.

    Regards.
    I am new to VB...

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Reading from website through VB

    Hai arnabbando,
    did not you try inet control (internet transfer control) ?
    that would do the work. also webbrowser control.
    tons of example can be found in the vbf code bank.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Guwahati, Assam, India
    Posts
    131

    Re: Reading from website through VB

    I have tried it with INet. Though I am programming in VB6 for quite some times now, but never needed to interact with internet before. I got the idea of using INet by seraching the vbforums only. Now when I am trying the following:

    Code:
    Dim strText As String
    
    strText = Inet1.OpenURL("http://www.wunderground.com/global/stations/42060.html")
    
    Open App.Path & "\test.txt" For Output As #1
        Print #1, strText
    Close #1
    What I am getting in the text file is this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Refresh" content="1800;URL=/global/stations/42060.html?MR=1" />
    <meta name="ICBM" content="32.33000183, 75.50000000" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline v2.0" l gen true for "http://www.wunderground.com" r (nz 0 vz 0 lz 0 oz 0 cz 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.wunderground.com" r (n 0 s 0 v 0 l 0))' />
    <title>Kathua, India Forecast : Weather Underground</title>
    <link rel="alternate" type="application/rss+xml" title="Kathua, India RSS" href="http://rss.wunderground.com/auto/rss_full/global/stations/42060.xml" />
    <link rel="stylesheet" type="text/css" href="http://icons-pe.wxug.com/css/wu2_base.css?v=2008060201" />
    <link rel="stylesheet" type="text/css" href="http://ic
    Offcourse this is not what I want. If you open the website http://www.wunderground.com/global/stations/42060.html in a browser, it is the five days forecast maximum and minimum temperatures that I want to read.

    Please help me.
    I am new to VB...

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Reading from website through VB

    If you have some knowledge on HTML basics, then you can also use MS Html object library to get the text in that webpage you shown. The values are kept inside <span> . so you can just retrive the inner text part of it.
    since the <span> element in that webpage does not contain an ID atribute, i am not sure how to identify each span element uniquely.

    so what i mean is, you can use the MS HTML Object library to retrieve that values.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Guwahati, Assam, India
    Posts
    131

    Re: Reading from website through VB

    I will try that. Thanks.

    However, meanwhile I tried to save the website from the browser as HTML and opened it through Microsoft FrontPage to view the HTML code behind. There the first few lines are matching with the text file I have posted earlier. But the whole code is much more than that. In the code, later it contains the temperature values which I think I can identify and read out.

    So what I want to ask is if it has something to do with maximum length of a string variable or something like that.

    Give me a clue.
    I am new to VB...

  6. #6
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Reading from website through VB

    Hope this example might give you some idea.
    Also this link. http://www.w3schools.com/HTMLDOM/default.asp
    Attached Files Attached Files

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Reading from website through VB

    Quote Originally Posted by arnabbandyo
    If you open the website http://www.wunderground.com/global/stations/42060.html in a browser, it is the five days forecast maximum and minimum temperatures that I want to read.
    Would something like this help get you started?
    Last edited by Edgemeal; Jan 5th, 2010 at 03:37 AM.

  8. #8
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Reading from website through VB

    Hi Edgmeal,
    Thanks for the post. i have one question also.

    If you have some knowledge on HTML basics, then you can also use MS Html object library to get the text in that webpage you shown. The values are kept inside <span> . so you can just retrive the inner text part of it.
    since the <span> element in that webpage does not contain an ID atribute, i am not sure how to identify each span element uniquely.
    When an Element has no ID specified, is there a way to uniquely identify it?

  9. #9
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Reading from website through VB

    Quote Originally Posted by Fazi
    Hi Edgmeal,
    Thanks for the post. i have one question also.
    When an Element has no ID specified, is there a way to uniquely identify it?
    I really don't know much at all about that stuff. If you look at the code I posted above it just uses the webbrower control to return the text of the webpage (html tags are removed), trims off some junk and the parses that text to get the result I was trying to archive.

    Edit The code can easily break if the web page changes,

    I forgot to finish the code so Celsius works....
    Code:
            Counter = 0
            For i = LINES To UBound(sArray)
                If InStr(1, sArray(i), " C") > 0 Then ' Changed " F" to " C" for Celsius
                    Counter = Counter + 1
                    If Counter = 1 Then
                        Text1 = Text1 & sArray(i) & "/"
                        TEMPS = TEMPS + 1
                    ElseIf Counter = 2 Then
                        Text1 = Text1 & sArray(i) & vbTab
                        Counter = 0
                        TEMPS = TEMPS + 1
                    End If
                    If TEMPS = 10 Then Exit For
                End If
            Next i
    Last edited by Edgemeal; Jul 4th, 2008 at 07:45 AM.

  10. #10
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Reading from website through VB

    OK Edgemeal,
    Actually if we can do what i was telling, that trimming also not requir. just we can directly get the text from the <span> eliment.

    Any way, what you have given is owsome.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Guwahati, Assam, India
    Posts
    131

    Thumbs up Re: Reading from website through VB

    What you have done will not only get me started, I think it is enough for me to finish the job.

    I don't have language to thank you.

    However, I knew that vbforums will be able to solve my problem since whatever I have learnt in VB is from this site only.
    I am new to VB...

  12. #12
    Junior Member iRoN_RoCK's Avatar
    Join Date
    Jul 2008
    Posts
    31

    Re: Reading from website through VB

    Quote Originally Posted by Fazi
    Hope this example might give you some idea.
    thank u so much Fazi. i was looking for an example like u gave. it solved one of my projects too but i have a question. i need to fill two textfields in a website but their name's are same in code. when i run ur code in mine, only first of them is filled. do u have a solution for that?

    and this is its code:

    Account Name: <input type='text' class="textfield" name='account'><br />
    <input type='image' target="_blank" src="images/top100.jpg" border="0" value='Vote' alt="Submit button" />
    </form>
    <br />
    <form action='vote/vote.php' target="_blank" method='post'>
    Account Name: <input type='text' class="textfield" name='account'><br />
    <input type='image' target="_blank" src="/images/xtremetop100.jpg" border="0" value='Vote' ALT="Submit button" /></form>
    </form>
    Last edited by iRoN_RoCK; Jul 5th, 2008 at 05:23 AM. Reason: additional info

  13. #13
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [RESOLVED] Reading from website through VB

    iRon,
    Hm, If i find a solution, i ll come back ok

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