吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3096|回复: 4
收起左侧

[已解决] (python) 如何将html代码转为word格式

[复制链接]
hj170520 发表于 2020-6-20 16:41
本帖最后由 hj170520 于 2020-6-25 16:43 编辑

上代码:
[HTML] 纯文本查看 复制代码
                <div class="entry-content">
                        <p><strong>Abduct</strong> and <strong>kidnap</strong> are sometimes employed without distinction as denoting to carry off (a person) surreptitiously for an illegal purpose.</p>
<h2>What’s the difference?</h2>
<p>In general use <strong>kidnap</strong> is the more specific term because it connotes seizure and detention for ransom. In law, however, the reverse is true, for the verbs acquire their meanings from the rigid technical definitions of kidnaping and abduction.</p>
<ul>
<li>Two businessmen have been <em>kidnapped</em> by terrorists.</li>
</ul>
<p><strong>Kidnaping</strong> is the legal term of wider application, implying that a person has been seized by violence or fraud and detained against his will or that of his legal guardian.</p>
<ul>
<li>She was arraigned today on charges of assault and <em>kidnapping</em>.</li>
</ul>
<p><strong>Abduction</strong> is the carrying off of a girl (usually one below the legal age of consent), either against her will or with her consent, for marriage or seduction.</p>
<ul>
<li>In some cases of <em>abduction</em>, the abducting parent is mentally unstable and/or a drug abuser.</li>
</ul>
<p>Consequently in law <strong>kidnaping</strong> and <strong>abduction</strong> and <strong>kidnap</strong> and <strong>abduct</strong> can be used interchangeably only when the person carried off is a girl below a fixed age, or when seizure and detention are against her will and the motive is marriage or rape.</p>
                                        </div><!-- .entry-content -->


如何用python实现? 还是说把代码直接导入word,在word里做手脚?
我的意思是如何把html的文字提取出来,并且在word里保留他们的格式。比如h2 就是heading2 ; <ul> 、<li> 就是编号。 而不显示这类的代码

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

rsnodame 发表于 2020-6-20 16:48
https://blog.csdn.net/qq_26535271/article/details/84500885
 楼主| hj170520 发表于 2020-6-20 16:57
rsnodame 发表于 2020-6-20 16:48
https://blog.csdn.net/qq_26535271/article/details/84500885

emmm,我的意思好像是把heading 部分 strong部分 以及编号部分保存他们的格式。

不过还是谢谢了,学到新的处理方式。
Ldfd 发表于 2020-6-20 17:39
wilison1992 发表于 2020-6-20 18:49
[Python] 纯文本查看 复制代码
import re
result = ""
with open('code.txt') as f:
    for line in f:
        temp = re.findall('>(.*?)<', line)
        if temp != []:
            temp = "".join(temp)
            result += temp

代码保存txt
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2025-1-15 20:49

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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