Quantcast
Viewing all articles
Browse latest Browse all 106

Parsing , tags value using feedparser in python from a Atom/xml feed

I am using feedparser for parsing data from an Atom/xml feed file. The link for the file is:

https://alerts.weather.gov/cap/oh.php?x=0

This is a feed that is put out by the National Weather Service for providing weather alert information. This feed uses a Common Alert Protocol (CAP) alert messaging. I'm trying to parse out the following:

<summary>...AIR QUALITY ADVISORY IN EFFECT UNTIL MIDNIGHT EDT TONIGHT... The Miami Valley Regional Planning Commission and the Regional Air Pollution Control Agency have issued an Air Pollution and Air Quality Advisory for Montgomery, Miami, Greene, Clark, Preble and Darke counties in the Miami Valley Region, until midnight EDT tonight.</summary><cap:event>Air Quality Alert</cap:event><cap:effective>2020-06-08T15:15:00-04:00</cap:effective><cap:expires>2020-06-09T19:30:00-04:00</cap:expires><cap:status>Actual</cap:status><cap:msgType>Alert</cap:msgType><cap:category>Met</cap:category><cap:urgency>Unknown</cap:urgency><cap:severity>Unknown</cap:severity><cap:certainty>Unknown</cap:certainty><cap:areaDesc>Clark; Darke; Greene; Miami; Montgomery; Preble</cap:areaDesc>

I can parse out the summary but I can't parse out the tags like or for example using feedparser. This is what I need for a Raspberry Pi project. I've tried many different approaches such as:

d = feedparser.parse('http://alerts.weather.gov/cap/ms.php?x=0')print (d.entries[0].['cap_event'])print (d.entries[0]['cap:event'])

When I try print (d.entries[0].['cap_event']), I get following error:

%Run feedparser2.py File "/home/n8mdp/MyPythonApps/feedparser2.py", line 13 print (d['entries'][0].['cap:event']) ^ SyntaxError: invalid syntax

If I use print (d.entries[0]['cap_event'], it get the following error:Traceback (most recent call last): File "/home/n8mdp/MyPythonApps/feedparser2.py", line 13, in print (d['entries'][0]['cap:event']) File "/home/n8mdp/.thonny/Python36/lib/python3.6/site-packages/feedparser.py", line 356, in getitem return dict.getitem(self, key)KeyError: 'cap:event'

Using Thonny 2.1.16 in Ubuntu 18.04.4 LTS. Feedparser is installed.

Does any one have a good suggestion on how I can parse those tags using feedparser in python?

Thanks in advance!


Viewing all articles
Browse latest Browse all 106

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>