Press "Enter" to skip to content

Python – How to Read XML from URL?

In Python, you can use urllib.request and xml.etree.ElementTree library to parse and read XML from URL. The following is an example:

Python Program Example – Read XML from URL

Below Python program will download and read the Oracle Database RSS feed through the URL. It will open the URL (https://blogs.oracle.com/oraclepartners/database-7/rss) using the urlopen method of urllib.request library and then it will parse and read the XML data using parse method of library xml.etree.ElementTree.

from urllib.request import urlopen
from xml.etree.ElementTree import parse

var_url = urlopen('https://blogs.oracle.com/oraclepartners/database-7/rss')
xmldoc = parse(var_url)

for item in xmldoc.iterfind('channel/item'):
    title = item.findtext('title')
    date = item.findtext('pubDate')
    link = item.findtext('link')

    print(title)
    print(date)
    print(link)
    print()

Output

Webcast: Oracle Database 19c: Strategy, Features & New Customers – April 9
Mon, 01 Apr 2019 13:09:04 +0000
https://blogs.oracle.com/oraclepartners/webcast%3A-oracle-database-19c%3A-strategy%2C-features-new-customers-%E2%80%93-april-9

Win Over Financial Services Prospects with MySQL Enterprise Edition 
Thu, 28 Mar 2019 21:10:44 +0000
https://blogs.oracle.com/oraclepartners/win-over-financial-services-prospects-with-mysql-enterprise-edition

How will you design the future for Data & Analytics? - April 26, 2019
Thu, 21 Mar 2019 12:38:22 +0000
https://blogs.oracle.com/oraclepartners/how-will-you-design-the-future-for-data-analytics-april-26%2C-2019

MySQL Enterprise Edition - High Availablity Campaign Now Available
Thu, 07 Mar 2019 23:00:00 +0000
https://blogs.oracle.com/oraclepartners/mysql-enterprise-edition-high-availablity-campaign-now-available

Stay Ahead of the Game with Autonomous Database Training
....

See also: