最开始解决方案有两种:
1) 使用正则表达式,匹配xml格式中的所有中文字符。
2) 使用BeautifulSoup的get_text()方法提取新闻内容
第一种方法,在进行中,后面更新
本文只展示第二种方法,因为无意之间发现了这个方法,简直不要太方便。
以下是初始文本,文本比较长,只展示了部分:
<?xml version="1.0" encoding="UTF-8"?>
<Body>
<Title>成都网友称震感强烈 女同事当即哭泣</Title>
<ReportTime type="absTime">2008年05月12日16:15</ReportTime>
<Content>
<Paragraph>
<Sentence>
<Event eid="e1">
<Time type="relTime" tid="t1">5月12日14时28分</Time>,
<Location lid="l1">四川</Location>发生7.8级
<Denoter type="emergency" did="d1">地震</Denoter>。
</Event>
</Sentence>
</Paragraph>
<Paragraph>
<Sentence>
<Event eid="e2">
<Time type="absTime" tid="t2">15时50分</Time>,新民网
<Participant sid="s1">记者</Participant>网上
<Denoter type="action" did="d2">连线</Denoter>成都网友
<Participant oid="o2">姚先生</Participant>
</Event>。
</Sentence>
<Sentence>
<Event eid="e3">
<Participant sid="s3,s4,s6,s7,s8,s9,s10">姚先生</Participant>
<Time type="relTime" tid="t3">当时</Time>正在
<Location lid="l3">成都市武侯区的办公室</Location>
<Denoter type="action" did="d3">打电话</Denoter>,
</Event>
<Event eid="e4" type=