吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1457|回复: 13
收起左侧

[Python 转载] 读取 ofd 内容 ,只是文字获取

[复制链接]
头像被屏蔽
rogabet 发表于 2023-12-8 11:14
提示: 作者被禁止或删除 内容自动屏蔽

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

T4DNA 发表于 2023-12-8 15:36
rogabet 发表于 2023-12-8 15:28
我智商不够,大师有办法优化?

我没有用过这个格式,但是比如你这底下的一堆
[Python] 纯文本查看 复制代码
                with open(xml_path10, "r", encoding="utf-8") as f:
                    _text10 = f.read()
                    tree10 = xmltodict.parse(_text10)
                    for row10 in tree10['ofd:Page']['ofd:Content']['ofd:Layer']['ofd:TextObject']:
                        data_dict10['ofd:TextCode'] = row10['ofd:TextCode'].get('#text')
                # return data_dict
 
                for i10 in range(0, 29939):
                    eachword10 = tree10['ofd:Page']['ofd:Content']['ofd:Layer']['ofd:TextObject'][i10][
                        'ofd:TextCode'].get(
                        '#text')
 
                    with open(os.getcwd() + '/ofdtxt/09.txt', "a") as f:
                        f.write(' ' + eachword10)


类似的代码,不可以用循环包起来吗?比如

[Python] 纯文本查看 复制代码
            for num in range(1, 36):
                xml_path = f"{file_path}/Doc_0/Pages/Page_{num}/Content.xml"
                try:
                    with open(xml_path, "r", encoding="utf-8") as f:
                        _text = f.read()
                        tree = xmltodict.parse(_text)
                        for row10 in tree['ofd:Page']['ofd:Content']['ofd:Layer']['ofd:TextObject']:
                            data_dict10['ofd:TextCode'] = row10['ofd:TextCode'].get('#text')
                    # return data_dict
    
                    for i10 in range(0, 29939):
                        eachword = tree['ofd:Page']['ofd:Content']['ofd:Layer']['ofd:TextObject'][i10][
                            'ofd:TextCode'].get(
                            '#text')
    
                        with open(os.getcwd() + f'/ofdtxt/{num}.txt', "a") as f:
                            f.write(' ' + eachword)
                except:
                    pass

免费评分

参与人数 1热心值 +1 收起 理由
ahtornado + 1 谢谢@Thanks!

查看全部评分

头像被屏蔽
 楼主| rogabet 发表于 2023-12-8 20:53
Hmily 发表于 2023-12-8 11:16
长得帅活得久 发表于 2023-12-8 11:47
其实OFD就是压缩包,打开里面就是xml
头像被屏蔽
 楼主| rogabet 发表于 2023-12-8 11:50
提示: 作者被禁止或删除 内容自动屏蔽
头像被屏蔽
 楼主| rogabet 发表于 2023-12-8 12:45
提示: 作者被禁止或删除 内容自动屏蔽
T4DNA 发表于 2023-12-8 15:01
这下面不能封装成函数吗?都是重复的代码
头像被屏蔽
 楼主| rogabet 发表于 2023-12-8 15:28
提示: 作者被禁止或删除 内容自动屏蔽
头像被屏蔽
 楼主| rogabet 发表于 2023-12-8 15:39
提示: 作者被禁止或删除 内容自动屏蔽
wpdzdx 发表于 2023-12-8 16:01
之前发的帖子被删除了  也没没看到
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 17:13

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表