xml解析与latex表示法

2024-06-07 22:01:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在阅读一些xml,其中的信息存储为

H.P. Dembinski, B. K\'{e}gl, I.C. Mari\c{s}, M. Roth, D. Veberi\v{c}

我想得到这个确切的格式,然而,我得到

^{pr2}$

所以我的问题是在我的处理步骤中哪里出错了? 这就是我要做的

today = some date
base_url = "http://export.arxiv.org/oai2?verb=ListRecords&"
url = (base_url + "from=%s&until=%s&" % (today, today) + "metadataPrefix=arXivRaw")

try:
    response = urllib2.urlopen(url)

except urllib2.HTTPError, e:
    return

rawdata = response.read()
root = ET.fromstring(rawdata)

if root.find(OAI+'ListRecords') is not None:
   for record in root.find(OAI+'ListRecords').findall(OAI+"record"):
     author_string = info.find(ARXIVRAW+"authors").text

我怎样才能阻止第二个\?我知道我可以做一些replace(),但一定有办法只得到原始文本? 谢谢 卡尔


Tags: 信息urlbasetodayresponserootxmlfind
1条回答
网友
1楼 · 发布于 2024-06-07 22:01:49

您看到的只是字符串的内部表示,它使用双\\来显示转义的反斜杠。如果打印字符串,您应该只看到一个\。示例-

>>> print(u"H.P. Dembinski, B. K\\'{e}gl, I.C. Mari\\c{s}, M. Roth, D. Veberi\\v{c}")
H.P. Dembinski, B. K\'{e}gl, I.C. Mari\c{s}, M. Roth, D. Veberi\v{c}

您还可以注意到开始处的u表示它是unicode字符串的内部表示形式。在

所以它很好,即使是在写文件时,等等。它应该可以正常工作,只有一个\会出现。在

相关问题 更多 >

    热门问题