$ python
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> e = ElementTree(file=urlopen("http://python.org"))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'ElementTree' is not defined
>>>
ElementTreeをインポートしたら問題なく動きました。
$ python
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> from elementtree.ElementTree import *
>>> e = ElementTree(file=urlopen("http://python.org"))
>>> for elem in e.getiterator():
... if elem.tag.endswith("}a"):
... print elem.get("href", "NONE")
...
.
#left-hand-navigation
#content-body
search
about
about/gettingstarted
about/apps
about/success
about/quotes
about/website
about/help
news
doc
download
community
psf
links
dev
download/releases/2.5