0

我使用某人的代码来创建过滤器。

import urllib2
import lxml.html as lh

req = urllib2.Request("http://www.ip-adress.com/ip_tracer/157.123.22.11", headers={'User-Agent' : "Magic Browser"})
html = urllib2.urlopen(req).read()
doc=lh.fromstring(html)
print ''.join(doc.xpath('.//*[@class="odd"]')[-1].text_content().split())

它将输出组织:ZenithDataSystems。但是当我运行它时,它显示了一些错误

Traceback (most recent call last):
File "ext.py", line 2, in ?
import lxml.html as lh
File "/usr/lib64/python2.4/site-packages/lxml/html/__init__.py", line 42, in ?
from lxml import etree
ImportError: /usr/lib64/python2.4/site-packages/lxml/etree.so: undefined symbol:       xmlMemDisplayLast

我以前没有使用过lxml。我的python版本是2.4.3,操作系统是CentOS release 5.5如何解决。当我更新 lxml 版本时,它显示

      Traceback (most recent call last):
      File "ext.py", line 3, in ?
      req= urllib2.Requset("http:// www.ip-address.com/ip_tracer/157.123.22.11", headers={'User-Agent' : "Magic Browser"})
      AttributeError: 'module' object has no attribute 'Requset'

谢谢,

4

1 回答 1

0

这是一个错误。您需要升级到lxml 3.0.1(或降级到lxml 2.3.6)。

pip install -U lxml==3.0.1

lxml 3.0.1错误修复GH#71: Failure to work with libxml2 2.6.x.

于 2012-10-16T03:55:25.257 回答