import urllib.request,urllib.parse,urllib.error
import xml.etree.ElementTree as ET
url=input('Enter location: ')
print('Retrieving',url)
uh=urllib.request.urlopen(url)
data=uh.read()
print('Retrieved',len(data),'characters')
tree=ET.fromstring(data)
counts=tree.findall('comments/comment')
sum=0
count=0
for item in counts:
sum+=int(item.find('count').text)
count+=1
print('Count:',count)
print('Sum',sum)
Using python to access web data week5 Assignment
最新推荐文章于 2021-10-19 04:23:50 发布