Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60082
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mr.cerutti@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.043 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.01; 'handler': 0.05; 'output': 0.05; 'level,': 0.07; 'namespace': 0.09; 'structure,': 0.09; 'subject:parsing': 0.09; 'val': 0.09; 'def': 0.12; '0.6': 0.16; 'either;': 0.16; 'handling,': 0.16; 'nesting': 0.16; 'subject:XML': 0.16; 'subject:item': 0.16; 'temp': 0.16; 'wrote:': 0.18; 'import': 0.22; "aren't": 0.24; 'parse': 0.24; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'larry': 0.31; 'class': 0.32; 'python.org': 0.32; 'info': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'building': 0.35; "didn't": 0.36; 'to:addr:python-list': 0.38; 'track': 0.38; '(from': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'subject:Fwd': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'hours': 0.66; 'jobs': 0.68; 'skip:w 40': 0.68; '(10': 0.84; 'exercise.': 0.84; 'temperature': 0.84; 'capture': 0.91; 'wilson': 0.91; 'choice.': 0.93; 'dirty': 0.93; 'wanting': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=J8TENpN2vnOxBbWg0z1aGW2Mvkw8ZZcBUPVGVqrER4A=; b=zatuILpnVFIhk87s8jeOsPkGoG3jM5yc94dUL6XxgpQ+buYy1fByLOGEh0PtcGwdFP MG727HLiXABcBNW3d/1KBU01HVmKsuif7oVSvpOvJq3jUzgTvy1QMXT7GEGmR11h/7eB HinkO9uIWMZHILdDBOQB4W05BghyLHYH3XEJUQeCNBeTyCjROVpOwBnVTnu1Pb63DRB+ vpW9idbgZhq9emEfIJ+F9pyXpxKS2sgV8TbuFc62ZER7oNXwFcPsAMOso0SAADpNfUXj jtVTF2wqLV1/vcwnJD8U+nbgS3J/bFK5PVbBE890n4eTf4n7TPiPG9wsFhkmAUgHqcwF ltUA== |
| MIME-Version | 1.0 |
| X-Received | by 10.180.211.71 with SMTP id na7mr26119979wic.5.1384958932452; Wed, 20 Nov 2013 06:48:52 -0800 (PST) |
| In-Reply-To | <CAHWX4tEMGiTYYRKyXOAFg-aZxeZYhh0vH-fAE8vxes=kbc5h3w@mail.gmail.com> |
| References | <bcd7481a-45c2-4dbb-a9e3-c5faa80ac899@googlegroups.com> <e3614644-c3fe-46e6-b5f1-7f285f1e81b1@googlegroups.com> <CAHWX4tEMGiTYYRKyXOAFg-aZxeZYhh0vH-fAE8vxes=kbc5h3w@mail.gmail.com> |
| Date | Wed, 20 Nov 2013 09:48:52 -0500 |
| Subject | Fwd: parsing RSS XML feed for item value |
| From | Neil Cerutti <mr.cerutti@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2963.1384958939.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384958940 news.xs4all.nl 15940 [2001:888:2000:d::a6]:52884 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:60082 |
Show key headers only | View raw
Larry Wilson itdlw1@gmail.com via python.org
10:39 PM (10 hours ago) wrote:
>
> Wanting to parse out the the temperature value in the
> "<w:current" element, just after the guid element using
> ElementTree or xml.sax.
Since you aren't building up a complex data structure, xml.sax
will be an OK choice.
Here's a quick and dirty job:
import io
import xml.sax as sax
the_xml = io.StringIO("""SNIPPED XML""")
class WeatherHandler(sax.handler.ContentHandler):
def startDocument(self):
self.temperatures = []
def startElement(self, name, attrs):
if name == 'w:current': # Nice namespace handling, eh?
self.temperatures.append(attrs)
handler = WeatherHandler()
sax.parse(the_xml, handler)
for temp in handler.temperatures:
for key, val in temp.items():
print("{}: {}".format(key, val))
Output (from your example):
windGusts: 29.6
dewPoint: 18.6
pressure: 0.0
windDirection: SSW
humidity: 90
rain: 0.6
temperature: 20.3
windSpeed: 22.2
For most jobs you would want to keep track of your nesting level, but
that's left out here. I didn't try to capture location or info you
might want but didn't specify, either; left that as an exercise.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
parsing RSS XML feed for item value Larry Wilson <itdlw1@gmail.com> - 2013-11-19 19:39 -0800
Re: parsing RSS XML feed for item value xDog Walker <thudfoo@gmail.com> - 2013-11-19 20:06 -0800
Re: parsing RSS XML feed for item value Larry Wilson <itdlw1@gmail.com> - 2013-11-20 05:44 -0800
Fwd: parsing RSS XML feed for item value Neil Cerutti <mr.cerutti@gmail.com> - 2013-11-20 09:48 -0500
Re: parsing RSS XML feed for item value xDog Walker <thudfoo@gmail.com> - 2013-11-20 08:17 -0800
Re: parsing RSS XML feed for item value xDog Walker <thudfoo@gmail.com> - 2013-11-20 08:31 -0800
Re: parsing RSS XML feed for item value Larry Wilson <itdlw1@gmail.com> - 2013-11-20 15:44 -0800
csiph-web