0 pts.
 retrieving information from an web site
I am trying to figure out how to search through HTML and retrieve certain information. such as loading the noaa weather Web site and and searching through the code and returning just the current temperature. I have seen this done using Java Script and even have the code to do it in java, but I need to do this in Visual Basic 6.0

Software/Hardware used:
ASKED: January 23, 2006  2:37 PM
UPDATED: January 27, 2006  8:21 AM

Answer Wiki:
You probably won't get much of a response on this site. It is related to SQL Server questions... Try a site related to HTML, Java or VB Cheers, Ben
Last Wiki Answer Submitted:  January 24, 2006  1:39 pm  by  BenjiT   0 pts.
All Answer Wiki Contributors:  BenjiT   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Here is an example of code. You will have to put in your own HTML tags as it won’t let me put them in here.

Public Function GetStuff() As Double
On Error GoTo ErrorHandler

Dim xmlDoc As New DOMDocument
Dim RequestLevel As IXMLDOMElement
Dim AddressLevel As IXMLDOMElement
Dim AddressElementLevel As IXMLDOMElement
Dim t As Variant
Dim i As Integer
Dim hOpen As Long, hConnection As Long, hFile As Long, numread As Long
Dim sHeader As String, htmlfile As String, tmp As String * 2048
Dim bDoLoop As Boolean
Dim WinHttpReq As WinHttp.WinHttpRequest
Dim MYSERVERNAME As String
Dim XmlString As String
Dim strTemp As String
Dim strResponse As String
Dim strStatus As String
Dim intLen As Integer

MYSERVERNAME = “web.site.address.here”

Set WinHttpReq = New WinHttpRequest
‘Here our proxy server is defined.
WinHttpReq.SetProxy 2, “YOUR.PROXY.SERVER.COM”

XmlString = MYSERVERNAME

WinHttpReq.Open “GET”, XmlString, False

WinHttpReq.Send

strResponse = Mid(WinHttpReq.ResponseText, InStr(WinHttpReq.ResponseText, “sometext”), 300)
strStatus = WinHttpReq.Status & ” – ” & WinHttpReq.StatusText
‘***** Handle error
If InStr(strResponse, “Error”) > 0 Then
intLen = InStr(strResponse, “endDescriptionTag”) – InStr(strResponse, “DescriptionTag”) – 13
strTemp = Mid(strResponse, InStr(strResponse, “DescriptionTag”) + 13, intLen)
MsgBox “There is an error of some type in the Address given.” & vbCrLf & _
strTemp & vbCrLf & “Please correct and try again!”, vbOKOnly
Exit Function
End If
‘**** Get specific Item You are looking for based on HTML tags and text within the HTML document
If InStr(strResponse, “text”) > 0 Then
‘**offset is the number of characters after the “text” I want to start at
strResponse = Mid(strResponse, InStr(strResponse, “text”) + offset, 100)
strResponse = Mid(strResponse, 1, InStr(strResponse, “endtag”) – 1)
GetExchangeRate = Val(Trim(strResponse))
End If

Exit Function
ErrorHandler:
MsgBox “Error # ” & Err.Number & ” has occurred!” & vbCr & _
Err.Description, vbOKOnly + vbExclamation, “ERROR GetStuff”
Resume Next
End Function

Have fun.
Stanton

 0 pts.

 

I do this all the time. The problem with the noaa site is that the temperature is not in a “tag” persay, it is just text on the page. Not only that, the user can rearrange the page making finding the text within the page difficult.

I use OZEXE (free to try; http://www.ozexe.com )as my tool of choice for this type of work. The following 5 lines of code will get the current temp from accuweather and display it:

DevOpen( IE )
DevWrite(IE,”URL”,”http://wwwa.accuweather.com/index-forecast.asp?partner=accuweather&myadc=0&zipcode=01507&u=1″)
cTemp = DevRead( IE, “text”, “Temperature:”, 10, 1 )
MsgBox( cTemp, “Current Temperature” )
DevClose( IE )

If you were to uncheck the “Display browser on open” checkbox in the device interface setup, you could do this behind the scenes.

The device interface for IE is very useful. Not only can you get text from a page, but you can read and write elements, hidden or visible, directly as well as run script and perform all navigation functions. Any time I need to get any data from anything or anywhere, I highly reccomend this tool.

 0 pts.

 

Thank you for all of your input I will try your suggestions and see what happens

 0 pts.