我需要一些帮助从python中的docx文档中检索脚注,因为docx文件包含大量脚注。
下面是我目前有一个问题的代码,因为docx2python 无法读取word文档,而不能比一定数量的pages更多地读取word文档。
from docx2python import docx2python
docx_temp = docx2python(filepath)
footnotes = docx_temp.footnotes
footnotes = footnotes[0][0][0]
footnotes = [i.replace("\t","") for i in footnotes]因此,我尝试了下面的其他方法,但是由于我不熟悉XML,所以我被困住了,而且我也不确定代码是否有效:
import re
import mammoth
with open(filepath, 'rb') as file:
html = mammoth.convert_to_html(file).value
#html = re.sub('\"(.+?)\"', '"<em>\1</em>"', html)
fnotes = re.findall('id="footnote-<number>" (.*?) ', html)和
import re
import zipfile
import xml.etree.ElementTree
from docx2python import docx2python
docxfile = zipfile.ZipFile(open(filepath,'rb'))
xmlString = docxfile.read('word/footnotes.xml').decode('utf-8')
fn = docxfile.read('word/footnotes.xml')
xml.etree.ElementTree.parse(fn)你们能告诉我如何正确地写代码从docx/HTML文件中提取脚注吗?谢谢你的帮忙!
发布于 2022-01-06 02:28:10
,因为docx2python不能读取超过特定页数的word文档。
几个月前,我重新编写了docx2python程序,以便从docx文件中复制一个结构化的(具有级别的) xml格式文件,这在许多文件上效果都很好。我不需要内容丢失。
您会尝试其他一些文件,或与我们共享您的文件,或者告诉我们您的certain number是什么。
据我所知,docx2python中的脚注源代码是作为这个footer = [x for y in footer for x in y]编写的。如果你用footnotes[0][0][0]来得到脚注,你可能会得到错误的注解。
https://stackoverflow.com/questions/59953921
复制相似问题