DEV Community

Durga Pokharel
Durga Pokharel

Posted on

2

Day 17 of 100Daysofcode :Extracting Data From XML

This is my day 17th of #100Daysofcode. Today I also continue to learned about python access on web data in Coursera..

Did many challenge in HTML regarding to the topic Introduction to the Responsive web Design challenge in Freecodecamp

Extracting Data From XML

Extensible markup language is a language that define set of rule for encoding documents in a formate that is both human readable and machine .
My code start from importing from urllib request and importing xml.etree.ElementTree as ET.

from urllib import request
import xml.etree.ElementTree as ET
Enter fullscreen mode Exit fullscreen mode

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.

url = "http://py4e-data.dr-chuck.net/comments_1113374.xml"
print ("Retrieving", url)
html = request.urlopen(url)
data = html.read()
print("Retrieved",len(data),"characters")

tree = ET.fromstring(data)
results = tree.findall('comments/comment')
icount=len(results)
isum=0

for result in results:
    isum += float(result.find('count').text)
print(icount)
print(isum)
Enter fullscreen mode Exit fullscreen mode

Day 17 of #100DaysOfCode and #Python
* I learned about python access on web data
* Did some challenge on extensible markup language
* Extracting data from XML pic.twitter.com/9us9a4c1zn

— Durga Pokharel (@mathdurga) January 10, 2021

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

AWS Industries LIVE! Stream

Business benefits of the cloud

Stream Industries LIVE! to explore innovative cloud solutions for modern businesses.

Learn More