in reply to Can't call method "getAttribute"

I would guess that the feed that the script uses to obtain weather information from has changed its layout or has ceased to exist since the script was written. There is nothing in the script that performs any much error checking so when things go pear shaped you don't get much that's helpful.


True laziness is hard work

Replies are listed 'Best First'.
Re^2: Can't call method "getAttribute"
by Squeakers (Initiate) on Jul 20, 2009 at 03:30 UTC
    This was a thought I had, and searching for yahoo weather rss feed i came up with a different url

    http://weather.yahooapis.com/forecastrss

    but i wasnt sure how to incorporate this into the code since the code seems to have 2 different urls

      I could be wrong here correct me if I am wrong. I tried to fetch the URL in the code with the variable replaced as in the code. i.e. (zipcode=60642 and unit=F) http://xml.weather.yahoo.com/forecastrss?p=60642&u=F
      I got following
      <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss +/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <title>Yahoo! Weather - Error</title> <description>Yahoo! Weather Error</description> <item> <title>City not found</title> <description> Invalid Input /forecastrss?p=60642&amp;u=F</description> </item> </channel> </rss><!-- api2.weather.ac4.yahoo.com compressed/chunked Sun Jul 19 22 +:10:00 PDT 2009 -->
      I tied the same for other zipcode (60641) and got following
      <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss +/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <title>Yahoo! Weather - Chicago, IL</title> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Chicago__IL/*http:/ +/weather.yahoo.com/forecast/USIL0225_f.html</link> <description>Yahoo! Weather for Chicago, IL</description> <language>en-us</language> <lastBuildDate>Sun, 19 Jul 2009 11:51 pm CDT</lastBuildDate> <ttl>60</ttl> <yweather:location city="Chicago" region="IL" country="US"/> <yweather:units temperature="F" distance="mi" pressure="in" speed="mph +"/> <yweather:wind chill="64" direction="0" speed="0" /> <yweather:atmosphere humidity="70" visibility="10" pressure="30.13" ri +sing="0" /> <yweather:astronomy sunrise="5:32 am" sunset="8:21 pm"/> <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url> </image> <item> <title>Conditions for Chicago, IL at 11:51 pm CDT</title> <geo:lat>41.84</geo:lat> <geo:long>-87.68</geo:long> <link>http://us.rd.yahoo.com/dailynews/rss/weather/Chicago__IL/*http:/ +/weather.yahoo.com/forecast/USIL0225_f.html</link> <pubDate>Sun, 19 Jul 2009 11:51 pm CDT</pubDate> <yweather:condition text="Partly Cloudy" code="29" temp="64" date="Sun +, 19 Jul 2009 11:51 pm CDT" /> <description><![CDATA[ ><img src="http://l.yimg.com/a/i/us/we/52/29.gif"/><br /> <b>Current Conditions:</b><br /> Partly Cloudy, 64 F<BR /> <BR /><b>Forecast:</b><BR /> Sun - Partly Cloudy. High: 71 Low: 54<br /> Mon - Sunny. High: 78 Low: 62<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Chicago__IL/*htt +p://weather.yahoo.com/forecast/USIL0225_f.html">Full Forecast at Yaho +o! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a> +)<br/> ]]></description> <yweather:forecast day="Sun" date="19 Jul 2009" low="54" high="71" tex +t="Partly Cloudy" code="29" /> <yweather:forecast day="Mon" date="20 Jul 2009" low="62" high="78" tex +t="Sunny" code="32" /> <guid isPermaLink="false">USIL0225_2009_07_19_23_51_CDT</guid> </item> </channel> </rss><!-- api2.weather.ac4.yahoo.com compressed/chunked Sun Jul 19 22 +:30:42 PDT 2009 -->
      If am not missing anything here the possible reason for the error is that yahoo is not returning any data for zip=60642 and there is no code to handle this condition therefore "$nodeset->get_node($index);" returns a undef value.
      I tried the same with "http://weather.yahooapis.com/forecastrss" and got the same results (no data for 60642), therefore I don't think changing URL will help. What you need is to handle the condition in the code.
      Regards,
      Ashish
        I noticed this also, when i open the weather.xml file i get garbage for 60642, so i changed this to an accurate chicago zipcode 60601. I still get the same error, cant call method getAttribute.

        Apparently 60642 isnt a recognized zipcode by yahoo, even though it is my correct zipcode.