【发布时间】:2016-10-03 09:26:51
【问题描述】:
import urllib
import xml.etree.ElementTree as ET
url = raw_input('Enter location: ')
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'
tree = ET.fromstring(data)
lst = tree.findall('.//count')
print 'Count:', len(lst)
total = 0
for comment in tree.findall("./comments/comment"):
total += int(comment.find('count').text)
print total
当我在 cmd 中运行上述代码时,我得到以下回溯
C:\Users\hp1\Downloads\python\programs>xml1.py
Traceback (most recent call last):
File "C:\Users\hp1\Downloads\python\programs\xml1.py", line 2, in <module>
import xml.etree.ElementTree as ET
File "C:\Users\hp1\Downloads\python\programs\xml.py", line 2, in <module>
import xml.etree.ElementTree as ET
ImportError: No module named etree.ElementTree
请帮忙,我不明白为什么会这样?
【问题讨论】:
标签: xml python-2.7 elementtree