Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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; 'lines.': 0.09; 'xml.': 0.09; 'python': 0.11; 'sections': 0.14; '"from': 0.16; '10:59': 0.16; '2.7.3': 0.16; 'angled': 0.16; 'brackets': 0.16; 'brackets.': 0.16; 'curve.': 0.16; 'dots': 0.16; 'preserve': 0.16; 'received:195.186': 0.16; 'received:bluewin.ch': 0.16; 'silly': 0.16; 'slash': 0.16; 'somewhere.': 0.16; 'statements,': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'examples': 0.20; 'fit': 0.20; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'builder': 0.24; 'of.': 0.24; 'parse': 0.24; "haven't": 0.24; 'skip:" 40': 0.26; 'tutorials': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'raise': 0.29; 'errors': 0.30; 'lines': 0.31; '"",': 0.31; 'bunch': 0.31; 'fault': 0.31; 'file': 0.32; 'summary': 0.32; '(most': 0.33; 'sense': 0.34; 'could': 0.34; "can't": 0.35; 'in.': 0.36; 'tech': 0.36; 'ubuntu': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'thank': 0.38; 'feed': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'recent': 0.39; '(from': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'break': 0.61; '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; 'urgent': 0.67; 'finance': 0.70; 'url:a': 0.72; 'cut': 0.74; 'url:jpg': 0.83; '"".': 0.84; 'again!': 0.84; 'all!': 0.84; 'experiment': 0.84; 'url:fi': 0.84; 'href="">': 0.91; 'url:l': 0.97 Date: Thu, 11 Jul 2013 14:25:13 +0200 From: "F.R." User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: ElementTree: can't figure out a mismached-tag error References: <51DE73E4.6040007@bluewin.ch> In-Reply-To: <51DE73E4.6040007@bluewin.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373545582 news.xs4all.nl 15944 [2001:888:2000:d::a6]:48336 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50437 On 07/11/2013 10:59 AM, 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 > > > > > > content="http://l.yimg.com/a/p/fi/31/09/00.jpg"> > > href="http://finance.yahoo.com/q?s=XIDEQ"> > 8 > 9 > ^ > Mismatch! > > Thanks for suggestions > > Frederic > Thank you all! I was a little apprehensive it could be a silly mistake. And so it was. I have BeautifulSoup somewhere. Having had no urgent need for it I remember shirking the learning curve. lxml seems to be a package with these components (from help (lxml)): PACKAGE CONTENTS ElementInclude _elementpath builder cssselect doctestcompare etree html (package) isoschematron (package) objectify pyclasslookup sax usedoctest I would start with "from lxml import html" and see what comes out. Break time now. Thanks again! Frederic