我在这里抓了一个网站就是结果:
Description
Cap: 4-9 cm Pale brown - often lighter towards the edge.
Viscid when wet.Gills: Pale clay-brown. Free. Gill edge exude droplets
when moist which dry to form dark spots.Stem: Off-white. Mealy towards
the apex.Spores: Clay-brownFlesh: Firm, white. Smell of
radishesHabitat: In groups or rings on the ground in mixed
woodlandFrequency: Very Common
我需要在冒号之前的单词之前添加一个滑架。 \ r \ nGills:为了使信息更具可读性。
re.sub()是最好的方法吗?
答案 0 :(得分:0)
text_with_rc=re.sub(r'\.\s*',r'.\r\n',the_text)
答案 1 :(得分:0)
是的,需要re.sub。尝试以下模式
str1=re.sub(r'(\w*:)',r'\r\n\1',string)
>>> print str1
Description
Cap: 4-9 cm Pale brown - often lighter towards the edge.
Viscid when wet.
Gills: Pale clay-brown. Free. Gill edge exude droplets
when moist which dry to form dark spots.
Stem: Off-white. Mealy towards
the apex.
Spores: Clay-
brownFlesh: Firm, white. Smell of
radishesHabitat: In groups or rings on the ground in mixed
woodlandFrequency: Very Common
>>>