1

我有这种格式来解析: 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'

问题是名字,如果我删除它一切正常。我该如何解决?

4

0 回答 0