如何从Python中的RSS提要中获取XML属性和值?
我在用雅虎!天气API来检索一些值。请求如下: 如何从以下内容中获取属性和值:如何从Python中的RSS提要中获取XML属性和值?,python,rss,Python,Rss,我在用雅虎!天气API来检索一些值。请求如下: 如何从以下内容中获取属性和值: <yweather:astronomy sunrise="6:20 am" sunset="4:52 pm"/> <yweather:condition text="Partly Cloudy" code="29" temp="14" date="Fri, 09 Nov 2012 1:47 am PST"/> 使用: 播放parse的结果,了解已解析提要的结构。使用: 播放parse的结果
<yweather:astronomy sunrise="6:20 am" sunset="4:52 pm"/>
<yweather:condition text="Partly Cloudy" code="29" temp="14" date="Fri, 09 Nov 2012 1:47 am PST"/>
使用:
播放parse
的结果,了解已解析提要的结构。使用:
播放
parse
的结果,了解已解析提要的结构。您可以使用feedparser
库执行此操作:
import feedparser
feed = feedparser.parse('http://weather.yahooapis.com/forecastrss?w=2442047&u=c')
print 'Sunrise:', feed.feed.yweather_astronomy['sunrise']
print 'Sunset:', feed.feed.yweather_astronomy['sunset']
您可以使用
feedparser
库执行此操作:
import feedparser
feed = feedparser.parse('http://weather.yahooapis.com/forecastrss?w=2442047&u=c')
print 'Sunrise:', feed.feed.yweather_astronomy['sunrise']
print 'Sunset:', feed.feed.yweather_astronomy['sunset']
@萨博但詹姆斯·亨斯特里奇的答案更好。@萨博但詹姆斯·亨斯特里奇的答案更好。
import feedparser
feed = feedparser.parse('http://weather.yahooapis.com/forecastrss?w=2442047&u=c')
print 'Sunrise:', feed.feed.yweather_astronomy['sunrise']
print 'Sunset:', feed.feed.yweather_astronomy['sunset']