#!/usr/local/bin/python3 import sys import urllib import urllib.request import urllib.parse from urllib.error import URLError, HTTPError import xml.etree.ElementTree as ET def getFeeds(): url = "http://kizasi.jp/kizapi.py?type=rank" # Print URL + Params try: response = urllib.request.urlopen(url, timeout=8) except HTTPError as e: print('The server couldn\'t fulfill the request.') print('Error code: ', e.code) except URLError as e: print('We failed to reach a server.') print('Reason: ', e.reason) return response.read() def do_xml(s): data = ET.fromstring(s) print(data.tag) found = data.findall(".//title") for s in found: if s.text == "kizasi.jp": continue print(s.text) if __name__ == "__main__": xml_str = getFeeds() d = xml_str.decode("utf-8") do_xml(d)