from pybtex.database.input import bibtex
#open a bibtex file
parser = bibtex.Parser()
bibdata = parser.parse_file("myrefs.bib")
#loop through the individual references
for bib_id in bibdata.entries:
b = bibdata.entries[bib_id].fields
try:
# change these lines to create a SQL insert
print b["title"]
print b["journal"]
print b["year"]
#deal with multiple authors
for author in bibdata.entries[bib_id].persons["author"]:
print author.first(), author.last()
# field may not exist for a reference
except(KeyError):
continue
老问题,但我现在正在使用Pybtex库做同样的事情,它有一个内置的解析器:
也可以使用Python BibtexParser:https://github.com/sciunto/python-bibtexparser
文档:https://bibtexparser.readthedocs.org
它非常直截了当(我在生产中使用)。
我不是这个图书馆的开发者。
转换成XML是个好主意。
XML作为一种独立于应用程序的数据格式存在,因此您可以使用现成的库来解析它;将它用作中介没有特别的缺点。事实上,您通常可以将XML导入数据库,甚至不必使用Python之类的编程语言(尽管您为这样的任务编写的Python数量微不足道)。
据我所知,Python没有直接、成熟的bibTeX阅读器。
相关问题 更多 >
编程相关推荐