首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python从docx转换的html文档中检索脚注(docx2python不起作用)

python从docx转换的html文档中检索脚注(docx2python不起作用)
EN

Stack Overflow用户
提问于 2020-01-28 17:16:19
回答 1查看 514关注 0票数 1

我需要一些帮助从python中的docx文档中检索脚注,因为docx文件包含大量脚注。

下面是我目前有一个问题的代码,因为docx2python 无法读取word文档,而不能比一定数量的pages更多地读取word文档。

代码语言:javascript
复制
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,所以我被困住了,而且我也不确定代码是否有效:

代码语言:javascript
复制
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)

代码语言:javascript
复制
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文件中提取脚注吗?谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

发布于 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]来得到脚注,你可能会得到错误的注解。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59953921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档