Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; 'output': 0.05; 'tree': 0.05; 'column': 0.07; 'parser': 0.07; 'lines.': 0.09; 'xml.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'sections': 0.14; '2.7.3': 0.16; 'angled': 0.16; 'brackets': 0.16; 'brackets.': 0.16; 'dots': 0.16; 'parser.': 0.16; 'preserve': 0.16; 'slash': 0.16; 'statements,': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'examples': 0.20; 'fit': 0.20; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'of.': 0.24; 'parse': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'skip:" 40': 0.26; 'tutorials': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'character': 0.29; 'raise': 0.29; 'xml': 0.29; "doesn't": 0.30; 'errors': 0.30; 'strongly': 0.30; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'too.': 0.31; '"",': 0.31; 'bunch': 0.31; 'fault': 0.31; 'file': 0.32; 'skip:c 30': 0.32; 'summary': 0.32; '(most': 0.33; 'skip:& 30': 0.33; 'sense': 0.34; 'could': 0.34; 'basic': 0.35; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'html,': 0.36; 'in.': 0.36; 'tech': 0.36; 'ubuntu': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'skip:& 10': 0.38; 'feed': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; 'subject:can': 0.39; 'skip:p 20': 0.39; 'space': 0.40; 'tag': 0.61; 'numbers': 0.61; 'first': 0.61; 'show': 0.63; 'stand': 0.64; 'url:p': 0.64; 'latest': 0.67; 'url:0': 0.67; 'finance': 0.70; 'url:a': 0.72; 'cut': 0.74; 'jul': 0.74; 'url:jpg': 0.83; '10:04,': 0.84; 'experiment': 0.84; 'href="': 0.84; 'to:addr:bluewin.ch': 0.84; 'url:fi': 0.84; 'url:l': 0.97; '2013': 0.98 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 :cc:content-type; bh=JwTr+yrKL/UVEopUNQCsT0wgHUSZDsKQAB4FwP+RJi0=; b=qLDpkMHrrLJQEPb/D4uEUvwBSL3Y9fe4LCgkpg7BUwEX8HegeUlFzqSStIsOWEgZ50 NfsbpVvNMBnpm2ejsYmSgpS26t8BLByFagSwECnFqZujGfLJMzeSrO4YuaCGqtRayZVh UMqsfKEO9+asF0gizKTGV3ry2BDT4R31TCO2O88RFPnQYhSdpEuv2DuAVwgrmnDFD0YK xM6AKDxaulugUPOQegNQLqdblWuW41KcTTm731wVA6YydzTi1YHB7h5SXTe9Jyenbehc 61BwQ9raTm/EWUArjjsDS1AxWYrs0Ne/p4rixcH0NGtIKjBJNNHPdOy/oDrjARBntBup covw== MIME-Version: 1.0 X-Received: by 10.229.141.10 with SMTP id k10mr7015064qcu.44.1373533684663; Thu, 11 Jul 2013 02:08:04 -0700 (PDT) In-Reply-To: <51DE73E4.6040007@bluewin.ch> References: <51DE73E4.6040007@bluewin.ch> Date: Thu, 11 Jul 2013 10:08:04 +0100 Subject: Re: ElementTree: can't figure out a mismached-tag error From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: "F.R." Content-Type: multipart/alternative; boundary=90e6ba3098a85c8e9d04e138bbfd Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 171 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373533692 news.xs4all.nl 15979 [2001:888:2000:d::a6]:33823 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50430 --90e6ba3098a85c8e9d04e138bbfd Content-Type: text/plain; charset=ISO-8859-1 On 11 Jul 2013 10:04, "F.R." wrote: > > Hi all, > > I haven't been able to get up to speed with XML. I do examples from the tutorials and experiment with variations. Time and time again I fail with errors messages I can't make sense of. Here's the latest one. The url is " http://finance.yahoo.com/q?s=XIDEQ&ql=0". Ubuntu 12.04 LTS, Python 2.7.3 (default, Aug 1 2012, 05:16:07) [GCC 4.6.3] > > >>> import xml.etree.ElementTree as ET > >>> tree = ET.parse('q?s=XIDEQ') # output of wget http://finance.yahoo.com/q?s=XIDEQ&ql=0 > Traceback (most recent call last): > File "", line 1, in > tree = ET.parse('q?s=XIDEQ') > File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse > tree.parse(source, parser) > File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse > parser.feed(data) > File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed > self._raiseerror(v) > File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror > raise err > ParseError: mismatched tag: line 9, column 2 > > Below first nine lines. The line numbers and the following space are hand-edited in. Three dots stand for sections cut out to fit long lines. Line 6 is a bunch of "meta" statements, all of which I show on a separate line each in order to preserve the angled brackets. On all lines the angled brackets have been preserved. The mismatched character is the slash of the closing tag . What could be wrong with it? And if it is, what about fault tolerance? > > 1 > 2 > 3 > 4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance > 5 > > > > > > > > > 8 > 9 > ^ > Mismatch! > > Thanks for suggestions > > Frederic That is not XML. It is HTML. You get a mismatched tag because the tag doesn't need closing in HTML, but in XML every single tag needs closing. Use an HTML parser. I strongly recommend BeautifulSoup but I think etree has an HTML parser too. I am not sure.. --90e6ba3098a85c8e9d04e138bbfd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 11 Jul 2013 10:04, "F.R." <anthra.norell@bluewin.ch> wrote:
>
> Hi all,
>
> I haven't been able to get up to speed with XML. I do examples fro= m the tutorials and experiment with variations. Time and time again I fail = with errors messages I can't make sense of. Here's the latest one. = The url is "http://finance.yahoo.com/q?s=3DXIDEQ&ql=3D0". Ubuntu 12.04 L= TS, Python 2.7.3 (default, Aug =A01 2012, 05:16:07) [GCC 4.6.3]
>
> >>> import xml.etree.ElementTree as ET
> >>> tree =3D ET.parse('q?s=3DXIDEQ') =A0# output of w= get http://fina= nce.yahoo.com/q?s=3DXIDEQ&ql=3D0
> Traceback (most recent call last):
> =A0 File "<pyshell#69>", line 1, in <module>
> =A0 =A0 tree =3D ET.parse('q?s=3DXIDEQ')
> =A0 File "/usr/lib/python2.7/xml/etree/ElementTree.py", line= 1183, in parse
> =A0 =A0 tree.parse(source, parser)
> =A0 File "/usr/lib/python2.7/xml/etree/ElementTree.py", line= 656, in parse
> =A0 =A0 parser.feed(data)
> =A0 File "/usr/lib/python2.7/xml/etree/ElementTree.py", line= 1643, in feed
> =A0 =A0 self._raiseerror(v)
> =A0 File "/usr/lib/python2.7/xml/etree/ElementTree.py", line= 1507, in _raiseerror
> =A0 =A0 raise err
> ParseError: mismatched tag: line 9, column 2
>
> Below first nine lines. The line numbers and the following space are h= and-edited in. Three dots stand for sections cut out to fit long lines. Lin= e 6 is a bunch of "meta" statements, all of which I show on a sep= arate line each in order to preserve the angled brackets. On all lines the = angled brackets have been preserved. The mismatched character is the slash = of the closing tag </head>. What could be wrong with it? And if it is= , what about fault tolerance?
>
> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD =A0. . . /strict.dtd"= ;>
> 2 <html lang=3D"en-US">
> 3 <head><meta http-equiv=3D"Content-Type" content= =3D"text/html; charset=3Dutf-8">
> 4 <title>XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance</t= itle>
> 5 <meta name=3D"description" xml:space=3D"default&qu= ot; content=3D"View the basic XIDEQ . . .
> 6 . . . other companies."><meta name=3D"keywords"= content=3D"XIDEQ, EXIDE TECH . . .">
> =A0 <meta property=3D"fb:app_id" content=3D"11815546= 8215844">
> =A0 <meta property=3D"fb:admins" content=3D"50376277= 0,100001149693905">
> =A0 <meta property=3D"og:type" content=3D"company&qu= ot;>
> =A0 <meta property=3D"og:site_name" content=3D"Yahoo= ! Finance">
> =A0 <meta property=3D"og:title" content=3D"Exide Tec= hnologies">
> =A0 <meta property=3D"og:image" content=3D"http://l.yimg.com/a/p/fi/31/09/0= 0.jpg">
> =A0 <meta property=3D"og:url" content=3D"http://finance.yahoo.com/q?s=3DXIDEQ<= /a>">
> =A0 <meta property=3D"og:description" content=3D"Vie= w the basic XIDEQ . . .
> 7 other companies."><link rel=3D"canonical" href= =3D"
http://finance.ya= hoo.com/q?s=3DXIDEQ">
> 8 <link rel=3D"stylesheet" href=3D"http://l.yimg.com/zz/ . . . type=3D"text/css"= ;>
> 9 </head>
> =A0 =A0^
> =A0 =A0 Mismatch!
>
> Thanks for suggestions
>
> Frederic

That is not XML. It is HTML. You get a mismatched tag becaus= e the <link> tag doesn't need closing in HTML, but in XML every s= ingle tag needs closing.

Use an HTML parser. I strongly recommend=A0 BeautifulSoup bu= t I think etree has an HTML parser too. I am not sure..

--90e6ba3098a85c8e9d04e138bbfd--