// An highlighted block
import urllib.request, urllib.parse, urllib.error
import xml.etree.ElementTree as ET
import ssl
import requests
txt = requests.get(url="http://py4e-data.dr-chuck.net/comments_196283.xml")
print(txt.text)
file = txt.text
tree = ET.fromstring(file)
lst = tree.findall('comments/comment')
print('Comment count:', len(lst))
SUM = 0
for item in lst:
name = item.find('name').text
count = int(item.find('count').text)
# print('Name',name)
# print('Count',count)
SUM = SUM + count
print(SUM)
ex_13_01.py
最新推荐文章于 2024-04-08 21:56:55 发布