无法从API返回数据中获取anies字段内容的技术咨询
无法提取ExLibris Alma API返回结果中的anies字段数据
我调用ExLibris Alma API后得到如下返回结果(已截断),其中anies字段是一个包含超过10000字符的XML字符串的数组,但尝试多种方法都无法提取该字段的数据,最多只能得到空列表。
{ "bib": [ { "mms_id": "################", "record_format": "marc21", "network_number": [ "(OCoLC)########", "(OCoLC)########", "(OCoLC)########" ], "place_of_publication": "Boston :", "holdings": { "link": "https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/#############/holdings" }, "created_by": "System", "created_date": "2021-02-03Z", "cataloging_level": { "value": "00", "desc": "Default Level" }, "brief_level": { "value": "10", "desc": "10" }, "anies": [ "<?xml version=\"1.0\" encoding=\"UTF-16\"?><record><leader>04746cam 2200697 i 4500</leader><controlfield ">1</subfield></datafield></record>" ] } ], "total_record_count": 1 }
尝试过的代码及结果
方法1:参照提取mms_id等字段的方式
for anies in root.findall('bib/anies'): print(anies.text)
结果:无输出,无法获取数据
方法2:参照提取holdings/link字段的方式
for child in root.findall('.//anies'): print(child) for num in root.findall('.//anies/'): b = num.attrib print(b)
结果:无有效输出
方法3:参照提取network_number字段的方式(与anies结构最接近)
e = root.findall('.//anies') print(e)
结果:返回空列表[]
补充说明
我并非需要打印anies字段内容,而是要在该字符串中查找特定文本,使用print仅用于快速验证是否成功提取数据。
内容的提问来源于stack exchange,提问作者czellib
相关产品推荐
相关产品推荐

