解析OAI2 / XML格式

时间:2019-02-12 21:04:47

标签: python api oai

我有这种格式可以解析:http://export.arxiv.org/oai2?verb=GetRecord&identifier=oai:arXiv.org:0804.2273&metadataPrefix=arXiv

所以我想得到作者的名字:

import urllib.request
import xml.etree.ElementTree as ET

response = urllib.request.urlopen(url_to_fetch)
xml = response.read()

root = ET.fromstring(xml)


for record in root.find(OAI+'ListRecords').findall(OAI+"record"):
    meta = record.find(OAI+'metadata')
    info = meta.find(ARXIV+"arXiv")
    authors = info.findall(ARXIV + 'authors/' + ARXIV + 'author')
    for author in authors:
        forenames = author.find(ARXIV+'forenames').text
        keyname = author.find(ARXIV+'keyname').text
        print(forenames)
        print(keyname)

但是我得到这个错误:

forenames = author.find(ARXIV+'forenames').text
AttributeError: 'NoneType' object has no attribute 'text'

问题出在眼前,如果我删除它,一切都会正常。我该如何解决?

0 个答案:

没有答案