次のファイルから温度と時間を取得したい:
<rss xmlns:georss="http://www.georss.org/georss" version="2.0">
<channel>
<title>Observations from Tunkhannock, PA - USA</title>
<link>
http://weather.weatherbug.com/PA/Tunkhannock-weather.html?ZCode=Z5546&Units=0&stat=TNKCN
</link>
<description>
Weatherbug, the owner of the world's largest weather network is now providing an API to it's weather data in the form of RSS. This will enable it's enthusiastic users to build their own applications.
</description>
<language>en-us</language>
<lastBuildDate>Sat, 05 Jan 2013 01:00:00 GMT</lastBuildDate>
<ttl>60</ttl>
<aws:weather xmlns:aws="http://www.aws.com/aws">
<aws:api version="2.0"/>
<aws:WebURL>
http://weather.weatherbug.com/PA/Tunkhannock-weather.html?ZCode=Z5546&Units=0&stat=TNKCN
</aws:WebURL>
<aws:InputLocationURL>
http://weather.weatherbug.com/PA/Tunkhannock-weather.html?ZCode=Z5546&Units=0
</aws:InputLocationURL>
<aws:station requestedID="" id="TNKCN" name="Tunkhannock HS" city="Tunkhannock" state=" PA" zipcode="18657" country="USA" latitude="41.5663871765137" longitude="-75.9794464111328"/>
<aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond002.gif">Partly Cloudy</aws:current-condition>
<aws:temp units="°F">30.3</aws:temp>
<aws:rain-today units=""">0</aws:rain-today>
<aws:wind-speed units="mph">1</aws:wind-speed>
<aws:wind-direction>WNW</aws:wind-direction>
<aws:gust-speed units="mph">20</aws:gust-speed>
<aws:gust-direction>WNW</aws:gust-direction>
</aws:weather>
<image>
<title>Local Weather from WeatherBug</title>
<width>142</width>
<height>18</height>
<link>
http://weather.weatherbug.com/PA/Tunkhannock-weather.html?ZCode=Z5546&Units=0&stat=TNKCN
</link>
<url>
http://www.weatherbug.com/aws/imagesHmPg0604/img_wxbug_logo_whiteBG.gif
</url>
</image>
<item>
<title>Live Conditions from Tunkhannock, PA - USA</title>
<link>
http://weather.weatherbug.com/PA/Tunkhannock-weather.html?ZCode=Z5546&Units=0&stat=TNKCN
</link>
<pubDate>Sat, 05 Jan 2013 01:54:00 GMT</pubDate>
<description>
<![CDATA[
<img src="http://deskwx.weatherbug.com/images/Forecast/icons/cond002.gif" border="0" alt="Current Conditions"/>
<b>Partly Cloudy</b> <br />
<b>Temperature:</b> 30.3 °F
<br />
<b>Wind Speed:</b> 1 mph WNW
<br />
<b>Gusts:</b> 20 mph WNW
<b>Rain Today:</b> 0 "
<br />
]]>
</description>
<georss:point>41.5663871765137 -75.9794464111328</georss:point>
<guid isPermaLink="false">Sat, 05 Jan 2013 01:54:21 GMT-Station1</guid>
</item>
</channel>
</rss
したがって、関連するデータは次の行になります。
<aws:temp units="°F">30.3</aws:temp>
と
<pubDate>Sat, 05 Jan 2013 01:54:00 GMT</pubDate>
私は何時間もググっていじりました。私はそのようにfeedparserを試しました:
import feedparser
d = feedparser.parse('http://api.wxbug.net/getLiveCompactWeatherRSS.aspx?ACode=A6787859817&zipcode=18657&unittype=0')
しかし、やっている
d.feed.temperature
機能しません(もちろん)。と
d.feed.aws_temp
単純に返す
{'units': u'°F'}
実際、私が d.feed を実行するとき、その中に温度についての言及はありません。誰かが私を正しい方向に向けることができますか? 私は python や feedparser に詳しくないので、実際の温度データ (30.3 度) が d.feed に記載されていない理由について混乱しています。
どんな提案でも大歓迎です!!
編集:BeautifulSoupは行くべき道のようです; 私が検索している間、私はそれに遭遇しませんでした。再度、感謝します!
私の質問は次のとおりです。これは、これを行うための好ましい方法ですか? やりたいことは、RRDTool を使用して気象データをグラフ化することだけです。それが私の家に最も近いので、私は WeatherBug からの温度を使用します。これはそれを行うための好ましい方法ですか?現在、weatherbug の Web ページをダウンロードし、適切な行を grep してデータをカットする非常に非効率的な bash スクリプトがあります。データが 4 文字を超える場合があるため、しばらくはうまく機能しません。
#/bin/bash
wget -q -O /home/colby/Scripts/conkyscripts/weather/fullPage "http://weather.weatherbug.com/PA/Tunkhannock-weather.html?zcode=z6286"
Time=`grep 'divObsTime' /home/colby/Scripts/conkyscripts/weather/fullPage | cut -c 41-49`
Temp=`grep -i 'divtemp' /home/colby/Scripts/conkyscripts/weather/fullPage | cut -c 59-62`
echo "As of $Time, it is $Temp"