2016-11-08 49 views
-3

我从网站获取了html并将其更改为txt。Python,只保留html的句子,并删除所有非英文字母,编号

但是,如何清理txt,以便我只保留txt中的句子。

例如:我想删除所有无关紧要的信息,如1990年...他自己,1987年,第59届....

保持句子:

汤姆·克鲁斯是美国演员谁拥有出演过许多大片电影,截至2012年是好莱坞收入最高的演员。他也是电影制片人并拥有一家制作公司。汤姆克鲁斯一直是三个金球奖的获得者,并被提名三次获得学院奖项。除此之外,许多电影巡航已经出演了票房巨大的大片。
在许多电影中反复成功之后,汤姆克鲁斯一直在继续发行两部任务不可能的电影,这是一场超级畅销票房的世界之战,还有更多。

等等。

1990 
... himself 
1987 
the 59th annual academy awards 
(tv special) 
jack 
/
maverick 
/
vincent lauria 
(uncredited) 
related videos 
none 
none 
none 
see all 35 videos  » 
@csm.csm_widget /> 
reality tv 
the office 
late night 
sitcoms 
music 
rappers 
action 
religion 
top paid 
how much money does tom cruise make? (salary & net worth) 
tom cruise is an american actor who has starred in many blockbuster movies and as of 2012 is the highest paid actor in hollywood. he is also a film producer and owns a production company. tom cruise has been the winner of three golden globe awards and has been nominated thrice for academy awards. apart from this, many of the movies cruise has starred in have been huge blockbusters on the box office. 
history 
thomas cruise mapother iv a.k.a tom cruise was born in syracuse, new york to mother mary lee and father thomas cruise mapother iii. cruise’s mother was a special education teacher and father was an electrical engineer. tom cruise is basically of irish, german and english origin. cruise’s family had the male domination of his abusive father whom cruise had once described as the merchant of chaos. he was often bullied and beaten by his father and cruise called him a coward. a part of tom cruise’s childhood was spent in canada. however, when cruise was in the sixth grade, his mother left his father and brought cruise and his siblings back to america. 
acting career 
acting career of tom cruise started quite early but with a small role in the movie endless love (1981). however, he got his big break as a supporting actor in the movie taps later that year. in 1983, his movies risky business and all the right moves along with top gun in 1986 paved the path for tom cruise as an established actor and a superstar. after this there was no looking back and tom cruise went to star in many super-successful movies like cocktail, rain man, days of thunder, interview with the vampire. 
then in 1996, he starred as a superspy ethan hunt in the very popular and blockbuster movie which went on to be a series, mission: impossible. that same year he also was seen in the lead role of the movie jerry maguire and won a golden globe for the same. in 1999, his supporting role in the movie magnolia again won him his second golden globe. 
after repeated success in many films, tom cruise kept going on with release of two mission impossible movies, war of the worlds which was a super duper box office hit and many more. 
net worth 
tom cruise’s films have gained $7.3 million worldwide as of 2013. however, the net worth of the highest paid actor in hollywood is $270 million and he still gets paychecks from his previous movies. 
154 magazine cover photos 
| 
none » 
official sites: 
facebook 
| 
official site 
| 
none 
» 
alternate names: 
tomu kurûzu 
height: 
5' 7" (1.7 m) 
none 
did you know? 
personal quote: 
(1992 quote) i really enjoy talking to other actors and directors. sometimes, if i see their movies, i'll call them up or write them a note saying, "i enjoyed it," or asking, "how did you do that? how did you make that work?". i just saw 

HTML文本被称为:文本

sentence = re.sub(' ', '\n', text) 
    sentence = re.sub('none', '', words) 

    print sentence 

结果:句子被破坏。

ethan 
hunt 
/
ray 
ferrier 
(uncredited) 
2006 
the 
late 
late 
show 
with 
craig 
ferguson 
(tv 
series) 
himself 
- 
episode 
#2.140 
(2006) 
... 
himself 
(uncredited) 
2006 
getaway 
(tv 
series) 
himself 
- 
seven 
wonders 
of 
the 
world 
(2006) 
... 
himself 
2006 
cmt 
insider 
(tv 
series) 
himself 
- 
episode 
dated 
29 
april 
2006 
(2006) 
... 
himself 
2005-2006 
corazón 
de... 
(tv 
series) 
himself 
- 
episode 
dated 
19 
january 
2006 
(2006) 
... 
himself 
- 
episode 
dated 
15 
november 
2005 
(2005) 
... 
himself 
- 
+0

看看Python的正则表达式。请注意,堆栈溢出不是一个代码写入服务。您需要努力工作,并在遇到特定问题时回来。 –

+0

我使用了正则表达式,但它将句子分成单独的单词 – HiPownedBi

+0

@HiPownedBi - 那么这将是很好的信息。你试过什么代码?你得到了什么错误? –

回答

1

试试这个:

^(\s*?\S*){5}$ 

代码当前设置为选择一些有5个字以内的任何行。您可以增加/改变{5}

演示的价值减少的单词数:https://regex101.com/r/z2qxrx/3

相关问题