鱼C论坛

 找回密码
 立即注册
查看: 1249|回复: 6

[已解决]如何提取文本中的指定内容?

[复制链接]
发表于 2021-1-16 14:24:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Zimeng 于 2021-1-16 14:24 编辑

最近用Kindle做读书笔记,突发奇想,如何用python提取摘抄内容,因为还没有入门,技术不精,百思不得其解。
示例在图片中,红线标注的是多余的地方,绿色是需要提取的地方。完整的文本在第二页,希望大佬们帮帮我!
最佳答案
2021-1-16 22:04:05
data = r"""==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #341-344的标注 | 添加于 2021年1月5日星期二 下午7:36:56

Apathy, the blunting of the emotions and the feeling that one could not care any more, were the symptoms arising during the second stage of the prisoner’s psychological reactions, and which eventually made him insensitive to daily and hourly beatings. By means of this insensibility the prisoner soon surrounded himself with a very necessary protective shell.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #357-358的标注 | 添加于 2021年1月5日星期二 下午7:48:25

congenitally dislocated hip. He was glad to be capable of working
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #516-519的标注 | 添加于 2021年1月5日星期二 下午8:42:11

The truth—that love is the ultimate and the highest goal to which man can aspire. Then I grasped the meaning of the greatest secret that human poetry and human thought and belief have to impart: The salvation of man is through love and in love. I understood how a man who has nothing left in this world still may know bliss, be it only for a brief moment, in the contemplation of his beloved.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-567的标注 | 添加于 2021年1月5日星期二 下午9:22:34

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed their daily portion of food by going. During the half-hour lunch interval
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-566的标注 | 添加于 2021年1月5日星期二 下午9:22:39

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-566的标注 | 添加于 2021年1月5日星期二 下午9:22:43

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed their daily portion of food by going.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:42

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber. Thus su ering
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:49

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber. Thus su ering
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:58

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #858-860的标注 | 添加于 2021年1月9日星期六 下午12:58:28

The experiences of camp life show that man does have a choice of action. There were enough examples, often of a heroic nature, which proved that apathy could be overcome, irritability suppressed. Man can preserve a vestige of spiritual freedom, of independence of mind, even in such terrible conditions of psychic and physical stress.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #860-863的标注 | 添加于 2021年1月9日星期六 下午12:58:59

We who lived in concentration camps can remember the men who walked through the huts comforting others, giving away their last piece of bread. They may have been few in number, but they o er su cient proof that everything can be taken from a man but one thing: the last of the human freedoms—to choose one’s attitude in any given set of circumstances, to choose one’s own way.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #870-871的标注 | 添加于 2021年1月9日星期六 下午1:01:33

Fundamentally, therefore, any man can, even under such circumstances, decide what shall become of him—mentally and spiritually. He may retain his human dignity even in a concentration camp. Dostoevski said once, “There is only one thing that I dread: not to be worthy of my su erings.”
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #880-884的标注 | 添加于 2021年1月10日星期日 下午4:43:44

The way in which a man accepts his fate and all the su ering it entails, the way in which he takes up his cross, gives him ample opportunity—even under the most di cult circumstances—to add a deeper meaning to his life. It may remain brave, digni ed and unsel sh. Or in the bitter ght for self-preservation he may forget his human dignity and become no more than an animal. Here lies the chance for a man either to make use of or to forgo the opportunities of attaining the moral values that a diffcult situation may afford him.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #913-914的标注 | 添加于 2021年1月10日星期日 下午4:54:45

that life in a concentration camp could be called a “provisional
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #918-922的标注 | 添加于 2021年1月10日星期日 下午4:57:48

A man who could not see the end of his “provisional existence” was not able to aim at an ultimate goal in life. He ceased living for the future, in contrast to a man in normal life. Therefore the whole structure of his inner life changed; signs of decay set in which we know from other areas of life. The unemployed worker, for example, is in a similar position. His existence has become provisional and in a certain sense he cannot live for the future or aim at a goal.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #995-997的标注 | 添加于 2021年1月10日星期日 下午6:31:50

Whenever there was an opportunity for it, one had to give them a why—an aim—for their lives, in order to strengthen them to bear the terrible how of their existence. Woe to him who saw no more sense in his life, no aim, no purpose, and therefore no point in carrying on.
==========
"""
import re
data = data.replace(r'Man\'s Search for Meaning.mobi (Frankl, Viktor)',' ')
text = re.findall(r'\b[A-Za-z].*',data)

for each in text:
    print(each)
    print('-------')
Screenshot 2021-01-16 at 1.46.03 PM.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-16 14:32:12 | 显示全部楼层
1. 提取是什么提取? 是从 文本中提取指定内容,还是从 照片中提取指定内容?
2. 想要提取的内容有什么特征? 没用过 kindle。 如果你的 摘抄是 英文,文章也是英文,又没什么区分条件,这怎么提取?
3. 提问题尽量描述清楚,不要开局一张图。 这种数据处理类的东西,好歹也要给定 测试数据 和 测试环境吧?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-16 14:44:31 | 显示全部楼层
°蓝鲤歌蓝 发表于 2021-1-16 14:32
1. 提取是什么提取? 是从 文本中提取指定内容,还是从 照片中提取指定内容?
2. 想要提取的内容有什么特 ...


1. 删除第二页中文本中多余的部分,照片中只是示例;
2. 两串‘=====’之间是一部分摘抄,其中上面的一串与空行之间是多余内容,包括书的标题,标注的位置与时间(为中文描述);其余为需要留下的摘抄部分,在第二页的文本中比较明显;
3. 抱歉没有描述清楚,期待您的回答
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-1-16 14:56:43 | 显示全部楼层
html = """
----------------------------------------------------------------
无效内容
无效内容

正式内容
正式内容
----------------------------------------------------------------
"""


s = html.split("\n\n")[1].replace("-", "")

类似上述的数据,代码就一行。
还有,问这种问题直接把数据发出来,不要只发张图,我们手上有没有那种数据,还得自己猜着来写。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-16 15:02:20 | 显示全部楼层
°蓝鲤歌蓝 发表于 2021-1-16 14:56
类似上述的数据,代码就一行。
还有,问这种问题直接把数据发出来,不要只发张图,我们手上有没有那种 ...

感谢您的回答
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-1-16 18:11:21 | 显示全部楼层
有规律的话可以不用正则表达式
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-1-16 22:04:05 | 显示全部楼层    本楼为最佳答案   
data = r"""==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #341-344的标注 | 添加于 2021年1月5日星期二 下午7:36:56

Apathy, the blunting of the emotions and the feeling that one could not care any more, were the symptoms arising during the second stage of the prisoner’s psychological reactions, and which eventually made him insensitive to daily and hourly beatings. By means of this insensibility the prisoner soon surrounded himself with a very necessary protective shell.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #357-358的标注 | 添加于 2021年1月5日星期二 下午7:48:25

congenitally dislocated hip. He was glad to be capable of working
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #516-519的标注 | 添加于 2021年1月5日星期二 下午8:42:11

The truth—that love is the ultimate and the highest goal to which man can aspire. Then I grasped the meaning of the greatest secret that human poetry and human thought and belief have to impart: The salvation of man is through love and in love. I understood how a man who has nothing left in this world still may know bliss, be it only for a brief moment, in the contemplation of his beloved.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-567的标注 | 添加于 2021年1月5日星期二 下午9:22:34

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed their daily portion of food by going. During the half-hour lunch interval
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-566的标注 | 添加于 2021年1月5日星期二 下午9:22:39

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #564-566的标注 | 添加于 2021年1月5日星期二 下午9:22:43

There were songs, poems, jokes, some with underlying satire regarding the camp. All were meant to help us forget, and they did help. The gatherings were so e ective that a few ordinary prisoners went to see the cabaret in spite of their fatigue even though they missed their daily portion of food by going.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:42

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber. Thus su ering
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:49

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber. Thus su ering
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #598-600的标注 | 添加于 2021年1月6日星期三 下午12:53:58

To draw an analogy: a man’s su ering is similar to the behavior of gas. If a certain quantity of gas is pumped into an empty chamber, it will ll the chamber completely and evenly, no matter how big the chamber.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #858-860的标注 | 添加于 2021年1月9日星期六 下午12:58:28

The experiences of camp life show that man does have a choice of action. There were enough examples, often of a heroic nature, which proved that apathy could be overcome, irritability suppressed. Man can preserve a vestige of spiritual freedom, of independence of mind, even in such terrible conditions of psychic and physical stress.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #860-863的标注 | 添加于 2021年1月9日星期六 下午12:58:59

We who lived in concentration camps can remember the men who walked through the huts comforting others, giving away their last piece of bread. They may have been few in number, but they o er su cient proof that everything can be taken from a man but one thing: the last of the human freedoms—to choose one’s attitude in any given set of circumstances, to choose one’s own way.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #870-871的标注 | 添加于 2021年1月9日星期六 下午1:01:33

Fundamentally, therefore, any man can, even under such circumstances, decide what shall become of him—mentally and spiritually. He may retain his human dignity even in a concentration camp. Dostoevski said once, “There is only one thing that I dread: not to be worthy of my su erings.”
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #880-884的标注 | 添加于 2021年1月10日星期日 下午4:43:44

The way in which a man accepts his fate and all the su ering it entails, the way in which he takes up his cross, gives him ample opportunity—even under the most di cult circumstances—to add a deeper meaning to his life. It may remain brave, digni ed and unsel sh. Or in the bitter ght for self-preservation he may forget his human dignity and become no more than an animal. Here lies the chance for a man either to make use of or to forgo the opportunities of attaining the moral values that a diffcult situation may afford him.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #913-914的标注 | 添加于 2021年1月10日星期日 下午4:54:45

that life in a concentration camp could be called a “provisional
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #918-922的标注 | 添加于 2021年1月10日星期日 下午4:57:48

A man who could not see the end of his “provisional existence” was not able to aim at an ultimate goal in life. He ceased living for the future, in contrast to a man in normal life. Therefore the whole structure of his inner life changed; signs of decay set in which we know from other areas of life. The unemployed worker, for example, is in a similar position. His existence has become provisional and in a certain sense he cannot live for the future or aim at a goal.
==========
Man\'s Search for Meaning.mobi (Frankl, Viktor)
- 您在位置 #995-997的标注 | 添加于 2021年1月10日星期日 下午6:31:50

Whenever there was an opportunity for it, one had to give them a why—an aim—for their lives, in order to strengthen them to bear the terrible how of their existence. Woe to him who saw no more sense in his life, no aim, no purpose, and therefore no point in carrying on.
==========
"""
import re
data = data.replace(r'Man\'s Search for Meaning.mobi (Frankl, Viktor)',' ')
text = re.findall(r'\b[A-Za-z].*',data)

for each in text:
    print(each)
    print('-------')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 09:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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