Solved

Reading data from another website (300 pts)

Posted on 2004-04-21
16
672 Views
Last Modified: 2012-05-04
I have a webpage that I am currently developing and I am trying to put the weather on it. I do not want to get the reading from instruments on location but instead get the general weather from a website. I have two different things that I am working on to try and get this to work:

ASP

<%@ Language="VBScript" %>
<%
     Dim whichfile, Content, fs, thisfile
      Content = ""
      Set fs = Server.CreateObject("Scripting.FileSystemObject")
      Set thisfile = fs.OpenTextFile("http://weather.allrefer.com/washington/harrington.html", 1, False)
      Content = thisfile.readall
      thisfile.Close

      set thisfile = Nothing
      set fs = Nothing

      T1.text = content
%>

VBScript

public sub loadweather()
Dim filesys, testfile
dim html as string
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile= filesys.OpenTextFile("http://weather.allrefer.com/washington/harrington.html", forreading, TristateUseDefault)
T1.text = testfile.readall
testfile.Close
end sub

Nothing happens with the VBScript and the ASP says:

Microsoft VBScript runtime error '800a0034'
Bad file name or number
/tests/vbs.asp, line 15

I don't care what I end up getting to work. Putting the text into T1 is just a test to see if the text got there. When it does I will use a substring, indexof, or something like that to pick out what I need, I got that part. I would almost prefer it to be in VBScript, just because I understand it better and could probably learn more from it, but it does not matter.

Thank you
0
Comment
Question by:cameraguy01
  • 5
  • 5
  • 3
  • +2
16 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10884083

I dont think you can give a url for filesystem object
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 300 total points
ID: 10884114
try this...

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  xml.Open "GET", "http://weather.allrefer.com/washington/harrington.html", False
      
  ' Actually Sends the request and returns the data:
  xml.Send

  Response.Write xml.responseText
 
 '''''T1.text = xml.responseText
 
  Set xml = Nothing
%>

0
 

Author Comment

by:cameraguy01
ID: 10884475
I think that we are close. I first put in the code how you gave it to me and it put the page in before T1 (which is the first and only thing on the test page). Then I deleted the Response.Write xml.responseText and uncommented the T1.text = xml.responsetext and when I tried it, it gave me this:

Microsoft VBScript runtime error '800a01a8'
Object required: 'responseText'
/tests/vbs.asp, line 26

If we can get it into T1 I think I can take it from there, obviously it is reading the page.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10884659
the code is working fine for me.

what is T1.text?
Is it a part of asp code or VBscript code...
0
 

Author Comment

by:cameraguy01
ID: 10885444
T1 is a text input on the page just to test to see if the html of the page is there. I think that T1.text is not what I was looking for, I think it was T1.value but I just tried that and it did not work either.
0
 

Author Comment

by:cameraguy01
ID: 10885480
Just to clarify this in case we are unclear, I am looking for the end result of this script to be a string of the HTML of the weather page that it opens. From that I can use the substring and indexof methods to pull out the current weather temperature at the time and display it on the page as I choose.
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10885775
xml.responseText contains the whole html file as a  string.
if you are getting any errors you might have to install Microsoft.XMLHTTP or MSXML2.ServerXMLHTTP on your server.
0
 
LVL 6

Expert Comment

by:sijpie
ID: 10886709
Your problem is with an undefined T1.text

I run the script as venkateshwarr has given it OK, and if I add this line
strT1 = xml.responseText
then I can parse strT1, and display the parts of it I want.

Nice one venkateshwarr!
0
 
LVL 6

Expert Comment

by:sijpie
ID: 10886738
As an aside, I am surprised that it does work for this particular site, as it seems to be a kind of framed site, and I would have thought that the text in the 'frames' would be inaccesible, but I can find any text I want in there so it does all get loaded in the string first. amazing.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 10888557
If you want weather, why not just subscribe to one of the many weather services? Or use an XML feed directly?
0
 
LVL 6

Expert Comment

by:sijpie
ID: 10888698
Yes, webwoman, but what if you want to display the weather in your website? That is what cameraguy is trying to achieve, by parsing a wether site, filtering out the information required and presenting that in his own webpage.

So using the xml method, he can now download the weather site as a string, parse it for the temperature say, and only display that piece of information. Pretty neat. i wonder what the implications are though if the weather site is off line or responding slowly. What will the penalty be then?
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10889519
I think webwoman has made a good suggestion, try contacting them and ask if they can provide something in XML format. The parsing may not work, if they update the website.
Everytime they update you have to update your page...
0
 
LVL 19

Assisted Solution

by:webwoman
webwoman earned 35 total points
ID: 10893507
If you want to display the weather, go to www.weatherunderground.com and put in your city. You can have the weather on your site, fed from them.

Or go to www.weather.com, click on weather tools in the top menu, and scroll down and look for 'weather on your web site'

I think the NWS has a text feed, or an XML one.

Why go through all that parsing when weather is available and easy to do?
0
 

Author Comment

by:cameraguy01
ID: 10895108
Alright, some answers for everyone

First, if I had to install Microsoft.XMLHTTP or MSXML2.ServerXMLHTTP then why would the weather page display on my page when I had the Response.Write xml.responseText part in there. Second, I don't see why I would be dealing with an undefined T1.Text. T1 is created before the script to put in the weather is run so it should be there. I might be able to get the text of the page into a variable but how do I display it to test? I get errors when I try using msgbox and I can't use a text input. Third, I realize that there would be problems with the page updating, I have thought about this. When I read through webwoman's comment I looked at the pages that she gave me. When I looked at NWS I saw that on this page (http://weather.noaa.gov/weather/current/KGEG.html) I could probably use a relative reference (substring + indexof) with 'latest' in that list toward the bottom. Webwoman and venkateshwarr are right, an XML feed would be better and I might have to contact them and ask them for that, but for now I think I want to try this. Finally, I do not want to get weather from these websites through their little box, image things. It is not that I have a problem with giving these websites their due, but I strongly feel that it is things like that that make a website look tacky. I try to keep a very consistent feel to pages I design and a big box that advertises for them (right there) with a feel of its own is not something I want. Besides, this might be in a scrolling display of messages along with time and such.

Thank you all for your comments

(I might be increasing the points and splitting them, everybody has brought something to this)
0
 

Author Comment

by:cameraguy01
ID: 10895112
I thought it might help if I included the code of my test page, just to see how things are.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>VBS</title>
</head>
<body>
<p><input type="text" name="T1" size="20"></p>
<%@ Language="VBScript" %>
<%
  Response.Buffer = True
  Dim objXMLHTTP, xml
  dim strT1

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  xml.Open "GET", "http://weather.allrefer.com/washington/harrington.html", False
     
  ' Actually Sends the request and returns the data:
  xml.Send
  strT1 = xml.responseText
  'T1.value = strT1.substring(50,5)    
  Set xml = Nothing
%>
</body>

</html>
0
 
LVL 2

Expert Comment

by:ricosuave
ID: 10897849
Hi CameraGuy01,

Your code should work, but it's a little sloppy ;)
You declare a variable called objXMLHTTP, but you never use it.
Instead you use the variable "xml" for your xml object.
I think that's a dangerous name, because it is also a property of the same (XMLHTTP) object. try this:

<%@ Language="VBScript" %>
<%
  Response.Buffer = True
  Dim objXMLHTTP
  Dim strT1

  ' Create an xmlhttp object:
  Set objXMLHTTP= Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set objXMLHTTP= Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  objXMLHTTP.Open "GET", "http://weather.allrefer.com/washington/harrington.html", False
     
  ' Actually Sends the request and returns the data:
  objXMLHTTP.Send
  strT1 = objXMLHTTP.responseText
  'T1.value = strT1.substring(50,5)    
 %>

<% Response.Write(strT1)%>

<%Set objXMLHTTP= Nothing%>

Please note that I left out the HTML tags you use in your version. I did that on purpose because the responseText will give you the -entire- HTML page, including <head> and <body>.  So if you response.write it in the body of an already existing page, you will get double tags.

If you save the code above to an .asp page and run it, you SHOULD see the weatherpage you are trying to reach. When you get to that point you may want to filter the HTML code you get back so you only show the part(s) that you need.

There are some functions for doing exactly that on this page:
http://www.precompiled.com/programming/ 

(scroll to the bottom)



0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Blog posts not showing up on Blog page 7 58
Animated .jpg? 13 77
stop navigation from wrapping 7 78
tomcat startup error 5 59
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question