API Response:http://iss.ndl.go.jp/api/opensearch?isbn=9784334770051 Hello, thanks for help yesterday. However when I attempt to get value from Elements I always get empty value as response. I were refereed this link However not sure I understand it. Where did I wrong and having empty value?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
import sys
import urllib
import urllib2
import re, pprint
from xml.etree.ElementTree import *
import csv
from xml.dom import minidom
import xml.etree.ElementTree as ET
import shelve
import subprocess
errorCheck = "0"
isbn = raw_input("Enter IBSN Number Please ")
isIsbn = len(isbn)
# ElementTree requires namespace definition to work with XML with namespaces correctly
# It is hardcoded at this point, but this should be constructed from response.
namespaces = {
'dc': 'http://purl.org/dc/elements/1.1/',
'dcndl': 'http://ndl.go.jp/dcndl/terms/',
}
# for prefix, uri in namespaces.iteritems():
# ElementTree.register_namespace(prefix, uri)
if isIsbn == 10 or isIsbn == 13:
errorCheck = 1
url = "http://iss.ndl.go.jp/api/opensearch?isbn=%s" % isbn
req = urllib2.Request(url)
response = urllib2.urlopen(req)
tree = ET.parse(response)
root = tree.getroot()
# root = ET.fromstring(XmlData)
print root.findall('dc:title', namespaces)
print root.findall('dc:title')
print root.findall('dc:identifier', namespaces)
print root.findall('dc:identifier')
print root.findall('identifier')
if errorCheck == "0":
print "It is not ISBN"
# print(root.tag,root.attrib)
# for child in root.find('.//item'):
# print child.text