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