【发布时间】:2015-06-25 07:48:02
【问题描述】:
我有一大堆从 Kindle 书籍中提取的 HTML。而且它有很多重复的元素和重复的子字符串。
长话短说,Kindle DRM 删除了我 90% 的注释,我使用它没有删除的位置数据将其全部恢复。但亚马逊的位置数据有些不精确(对应 150 字节的块),所以我最终得到了很多冗余。
例子:
<html>
<body>
<p>
aesar”), at the Battle of Pavia (1525).
</p>
<div height="0em">
</div>
<mbp:pagebreak>
</mbp:pagebreak>
<a id="filepos97755">
</a>
<h1 align="center" height="2em">
<font size="5">
<b>
KNOW WHEN
<br/>
TO RETIRE
</b>
</font>
</h1>
<div height="3em">
</div>
<p align="justify" height="0em" width="1em">
</p>
</body>
</html>
<html>
<body>
<h1 align="center" height="2em">
<font size="5">
<b>
KNOW WHEN
<br/>
TO RETIRE
</b>
</font>
</h1>
<div height="3em">
</div>
<p align="justify" height="0em" width="1em">
Anything in motion must wax and wane. Some speak of states of movement, but they are anything but static.
</p>
<div height="0em">
</div>
<p height="0em">
</p>
</body>
</html>
<html>
<body>
<p align="justify" height="0em" width="1em">
Anything in motion must wax and wane. Some speak of states of movement, but they are anything but static.
</p>
<div height="0em">
</div>
<p align="justify" height="0em" width="1em">
It takes great foresight to predict the decline of a restless, relentless wheel. The sharpest gamblers know when to quit
</p>
</body>
</html>
有没有人知道什么会有所帮助?
【问题讨论】:
-
这很简单,学习你喜欢的语言的字符串和输入处理并编写代码,然后如果有任何错误在这里发布。你可以使用这个包docs.python.org/2/library/htmlparser.html
标签: python html parsing screen-scraping redundancy