【问题标题】:Using textract to get text from pptx. and docx. without tags [duplicate]使用 textract 从 pptx 获取文本。和docx。没有标签[重复]
【发布时间】:2020-02-11 13:11:51
【问题描述】:

我使用以下代码从 docx 获取字符串。或pptx。 (由于 textract 不能正确使用非 acsii 符号,我使用here 描述的解决方案):

import textract as txt
text = txt.process("D:\Corpus\Exposee.pptx")
text = text.decode("utf8")

然后我调用text 得到如下字符串:

'Syntaktische Besonderheiten \n\ndes Maschinellen Verstehens \n\nder Deutschen Sprache \n\nin der Multilingualen Perspektive\n\nMarvin Teller\n\nForschungsfrage\n\nW\n\nelche\n\n \n\nEigenschaften\n\n \n\n\n\n\tder \n\nsyntaktischen\n\n \n\nStruktur\n\n der \n\n

(缩短)

我想要没有\n\t 等标签的字符串,该怎么做?

对于可能的重复/幼稚,请提前道歉

【问题讨论】:

  • 你称它为基础版本,\n 允许段落,尝试使用 print(text) 然后你会明白我的意思
  • 但如果你确实想删除它,请执行 text = text.remove()
  • @TommyLawrence 感谢您的建议!但是,在将 'remove' 应用于字符串(文本)时,我得到“AttributeError:'str' object has no attribute 'remove'”
  • 好吧,对不起,是替换,做 text = text.replace("\n", "")
  • 这能回答你的问题吗? Remove all line breaks from a long string of text

标签: python tags powerpoint text-extraction


【解决方案1】:

基于 cmets: 您看到的文本是您从文件中提取的形式。 \n 允许你有段落。通过放置该文本(字符串)并打印它,您可以看到它生成了段落。要摆脱它,您需要执行 text (variable) = text.replace("\n", ""),这会将 "\n" 替换为空 ""。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2023-03-10
    • 1970-01-01
    • 2013-10-30
    相关资源
    最近更新 更多