我使用此代码来获得IP地址的组织的Python 3.2.3运行错误
import urllib
import lxml.html as lh
req= urllib.Request("http://www.ip-address.com/ip_tracer/157.123.22.11", headers={'User-Agent' : "Magic Browser"})
html = urllib.urlopen(req).read()
doc = lh.fromstring(html)
print (''.join(doc.xpath('.//*[@class="odd"]')[-1].text_content().split()))
我的Python 3.2.3是,它显示了
Traceback (most recent call last):
File "ext.py", line 3, in <module>
req= urllib.Request("http:// www.ip-address.com/ip_tracer/157.123.22.11", headers={'User-Agent' : "Magic Browser"})
AttributeError: 'module' object has no attribute 'Request'
如何解决这个问题。谢谢,
BTW:是对空间在'http://'和'www.ip-address.com'之间有用吗? – glglgl
请不要编辑这样的问题。您的原始问题已被回答。接受一个答案并为你的新问题开一个新的问题。 – 2012-10-17 08:49:48
这个问题被标记为urllib3,有什么理由吗? – shazow