我正在尝试使用ElementTree python库导入从Scopus下载的XML文件。
这是我实际代码的两个片段,它们都返回相同的错误:
1)
import urllib2
import xml.etree.ElementTree as ET
url = 'https://api.elsevier.com/content/search/scopus?query=au-id(' + author_id + ')&apiKey=' + apiKey_standard
xml = urllib2.urlopen(url).read()
tree = ET.fromstring(xml)2)
import urllib2
import xml.etree.ElementTree as ET
url = 'https://api.elsevier.com/content/search/scopus?query=au-id(' + author_id + ')&apiKey=' + apiKey_standard
xml = urllib2.urlopen(url)
tree = ET.parse(xml)错误:
xml.etree.ElementTree.ParseError:格式不正确(无效令牌):第1行,第0列
如果我打印,从片段1),print xml[0],我得到{。
看来,urllib2 read方法返回一个json对象。
发布于 2017-04-10 11:27:46
向查询中添加&httpAccept=application%2Fatom%2Bxml参数以指定所需的格式:
url = 'https://api.elsevier.com/content/search/scopus?query=au-id(' + author_id + ')&apiKey=' + apiKey_standard + '&httpAccept=application%2Fatom%2Bxml'https://stackoverflow.com/questions/43321881
复制相似问题