Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50437

Re: ElementTree: can't figure out a mismached-tag error

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 <anthra.norell@bluewin.ch>
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." <anthra.norell@bluewin.ch>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4582.1373545582.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 "<pyshell#69>", line 1, in <module>
>     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 </head>. What could be wrong 
> with it? And if it is, what about fault tolerance?
>
> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD  . . . /strict.dtd">
> 2 <html lang="en-US">
> 3 <head><meta http-equiv="Content-Type" content="text/html; 
> charset=utf-8">
> 4 <title>XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance</title>
> 5 <meta name="description" xml:space="default" content="View the basic 
> XIDEQ . . .
> 6 . . . other companies."><meta name="keywords" content="XIDEQ, EXIDE 
> TECH . . .">
>   <meta property="fb:app_id" content="118155468215844">
>   <meta property="fb:admins" content="503762770,100001149693905">
>   <meta property="og:type" content="company">
>   <meta property="og:site_name" content="Yahoo! Finance">
>   <meta property="og:title" content="Exide Technologies">
>   <meta property="og:image" 
> content="http://l.yimg.com/a/p/fi/31/09/00.jpg">
>   <meta property="og:url" content="http://finance.yahoo.com/q?s=XIDEQ">
>   <meta property="og:description" content="View the basic XIDEQ . . .
> 7 other companies."><link rel="canonical" 
> href="http://finance.yahoo.com/q?s=XIDEQ">
> 8 <link rel="stylesheet" href="http://l.yimg.com/zz/ . . . 
> type="text/css">
> 9 </head>
>    ^
>     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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: ElementTree: can't figure out a mismached-tag error "F.R." <anthra.norell@bluewin.ch> - 2013-07-11 14:25 +0200
  Re: ElementTree: can't figure out a mismached-tag error fronagzen@gmail.com - 2013-07-11 05:49 -0700

csiph-web