提取xml格式新闻内容

最开始解决方案有两种:
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=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值