in  my computer,there two os ,<br>1.xp+python32<br>import lxml.html<br>sfile='http://finance.yahoo.com/q/op?s=A+Options' root=lxml.html.parse(sfile).getroot()<br><div><includetail><div> it is ok<br> import lxml.html<br>sfile='http://frux.wikispaces.com/'<br>root=lxml.html.parse(sfile).getroot()<br>there is problem <br></div>Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>  File "C:\Python32\lib\site-packages\lxml\html\__init__.py", line 692, in parse<br><br>    return etree.parse(filename_or_url, parser, base_url=base_url, **kw)<br>  File "lxml.etree.pyx", line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:5<br>4187)<br>  File "parser.pxi", line 1528, in lxml.etree._parseDocument (src/lxml/lxml.etre<br>e.c:79485)<br>  File "parser.pxi", line 1557, in lxml.etree._parseDocumentFromURL (src/lxml/lx<br>ml.etree.c:79768)<br>  File "parser.pxi", line 1457, in lxml.etree._parseDocFromFile (src/lxml/lxml.e<br>tree.c:78843)<br>  File "parser.pxi", line 997, in lxml.etree._BaseParser._parseDocFromFile (src/<br>lxml/lxml.etree.c:75698)<br>  File "parser.pxi", line 564, in lxml.etree._ParserContext._handleParseResultDo<br>c (src/lxml/lxml.etree.c:71739)<br>  File "parser.pxi", line 645, in lxml.etree._handleParseResult (src/lxml/lxml.e<br>tree.c:72614)<br>  File "parser.pxi", line 583, in lxml.etree._raiseParseError (src/lxml/lxml.etr<br>ee.c:71927)<br>IOError: Error reading file 'b'http://frux.wikispaces.com/'': b'failed to load e<br>xternal entity "http://frux.wikispaces.com/"'<br><br>2. ubuntu11.04+python2.6<br></includetail>import lxml.html<br>
sfile='http://frux.wikispaces.com/'<br>
root=lxml.html.parse(sfile).getroot()<br>it is ok<br>it is so strange thing for me to understand<br><includetail><div style="font:Verdana normal 14px;color:#000;"><div style="FONT-SIZE: 12px;FONT-FAMILY: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="FONT-SIZE: 12px;background:#efefef;padding:8px;"><div id="menu_sender"><b>发件人:</b> "Dave Angel"<d@davea.name>;</div><div><b>发送时间:</b> 2011年10月24日(星期一) 上午9:22</div><div><b>收件人:</b> "1248283536"<1248283536@qq.com>; <wbr></div><div><b>抄送:</b> "lxml"<lxml@lxml.de>; "python-list"<python-list@python.org>; <wbr></div><div><b>主题:</b> Re: getroot()   problem</div></div><div> </div>
On 10/23/2011 09:06 PM, 水静流深 wrote:<br>> C:\Documents and Settings\peng>cd c:\python32<br>><br>><br>><br>> C:\Python32>python<br>><br>> Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win<br>><br>> 32<br>><br>> Type "help", "copyright", "credits" or "license" for more information.<br>><br>>>>> import lxml.html<br>><br>>>>> sfile='http://finance.yahoo.com/q/op?s=A+Options'<br>><br>>>>> root=lxml.html.parse(sfile).getroot()<br>> there is no problem to  parse  :<br>><br>><br>> http://finance.yahoo.com/q/op?s=A+Options'<br>><br>><br>><br>><br>> why  i can not parse<br>><br>> http://frux.wikispaces.com/  ??<br>><br>>>>> import lxml.html<br>><br>>>>> sfile='http://frux.wikispaces.com/'<br>><br>>>>> root=lxml.html.parse(sfile).getroot()<br>><br>> Traceback (most recent call last):<br>><br>>    File "<stdin>", line 1, in<module><br>><br>>    File "C:\Python32\lib\site-packages\lxml\html\__init__.py", line 692, in parse<br>><br>><br>><br>>      return etree.parse(filename_or_url, parser, base_url=base_url, **kw)<br>><br>>    File "lxml.etree.pyx", line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:5<br>><br>> 4187)<br>><br>>    File "parser.pxi", line 1528, in lxml.etree._parseDocument (src/lxml/lxml.etre<br>><br>> e.c:79485)<br>><br>>    File "parser.pxi", line 1557, in lxml.etree._parseDocumentFromURL (src/lxml/lx<br>><br>> ml.etree.c:79768)<br>><br>>    File "parser.pxi", line 1457, in lxml.etree._parseDocFromFile (src/lxml/lxml.e<br>><br>> tree.c:78843)<br>><br>>    File "parser.pxi", line 997, in lxml.etree._BaseParser._parseDocFromFile (src/<br>><br>> lxml/lxml.etree.c:75698)<br>><br>>    File "parser.pxi", line 564, in lxml.etree._ParserContext._handleParseResultDo<br>><br>> c (src/lxml/lxml.etree.c:71739)<br>><br>>    File "parser.pxi", line 645, in lxml.etree._handleParseResult (src/lxml/lxml.e<br>><br>> tree.c:72614)<br>><br>>    File "parser.pxi", line 583, in lxml.etree._raiseParseError (src/lxml/lxml.etr<br>><br>> ee.c:71927)<br>><br>> IOError: Error reading file 'b'http://frux.wikispaces.com/'': b'failed to load e<br>><br>> xternal entity "http://frux.wikispaces.com/"'<br>><br>>>> ><br>Double-spacing makes your message much harder to read. I can only <br>comment in a general way, in any case. most html is mal-formed, and not <br>legal html. Although I don't have any experience with parsing it, I do <br>with xml which has similar problems.<br><br>The first thing I'd do is to separate the loading of the byte string <br>from the website, from the parsing of those bytes. Further, I'd make a <br>local copy of those bytes, so you can do testing repeatably. For <br>example, you could run wget utility to copy the bytes locally and create <br>a file.<br>-- <br><br>DaveA<br><br><br></div></includetail></div>