- 论坛徽章:
- 0
|
学习urllib2模块时,下面脚本提示错误,但是复制到ipython环境中就能正常运行,和解?
#!/usr/bin/python
import urllib2
import time
hosts = ["http://yahoo.com","http://ibm.com","http://amazon.com","http://www.baidu.com","http://sina.com.cn"]
start = time.time()
#grabs urls of hosts and prints firest 1024 bytes of page
for host in hosts:
url = urllib2.urlopen(host)
print url.read(1024)
print "Elapsed Time: %s" % (time.time() - start)
OUTPUT:
root@ubuntu:/python# ./urllib2.py
Traceback (most recent call last):
File "./urllib2.py", line 3, in <module>
import urllib2
File "/python/urllib2.py", line 12, in <module>
url = urllib2.urlopen(host)
AttributeError: 'module' object has no attribute 'urlopen'
|
|