【题解】Extracting Data from XML (Using Python to Access Web Data)

本文介绍了如何使用Python从XML数据中提取评论计数并计算总和。通过urllib获取XML数据,使用ElementTree库解析并查找所有'count'标签,然后将文本转换为整数并求和。同时,提到了decode和encode在处理字符串编码时的区别。
摘要由CSDN通过智能技术生成

吐槽:挺简单的,但还是想记一下,主要是decode和encode以前忘记记录了。

题目:Extracting Data from XML

In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/geoxml.py. The program will prompt for a URL, read the XML data from that URL using urllib and then parse and extract the comment counts from the XML data, compute the sum of the numbers in the file.

We provide two files for this assignment. One is a sample file where we give you the sum for your testing and the other is the actual data you need to process for the assignment.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值