免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2189 | 回复: 1
打印 上一主题 下一主题

新手学习python,求大神帮忙提取下以下数据 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-12-09 23:35 |只看该作者 |倒序浏览

SUCC:_BOSSXML.MCN:MMOSReq:Retn=0000,Desc=处理成功,INFO={"MMOSReq":{"MSISDN":"13822214928","FollowMSISDN":"15711728080","Seq":"0218BIP5A01120151031234446012952","OprCode":"06","BizType":"74","Channel":"70","ChrgType":"2","Category":"0","SerialNum":"1","EffectiveTime":"20151031234446","SPID":"698034","SPServID":"100000"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120151031234447104062","TransIDO":"BIP5A01120151031234447104062","TransIDOTime":"20151031234447","MsgSender":"2001"},"MMOSRsp":{"MSISDN":"13822214928","FollowMSISDN":"15711728080","Seq":"0218BIP5A01120151031234446012952","BizOrderResult":"0000","ResultDesc":"业务受理成功"
ERROR:_BOSSXML.MCN:MMOSReq:Retn=2998,Desc=其他错误,INFO={"MMOSReq":{"OprCode":"06","MSISDN":"13888545543","SPID":"698034","SPServID":"100000","Seq":"0218BIP5A01120150901011849010345","FollowMSISDN":"15198712767","ChrgType":"2","Category":"0","SerialNum":"1","Channel":"70","BizType":"74","EffectiveTime":"20150901011849"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120150901011850021785","TransIDO":"BIP5A01120150901011850021785","TransIDOTime":"20150901011850","MsgSender":"0218"},"MMOSRsp":{"MSISDN":"13888545543","FollowMSISDN":"15198712767","Seq":"0218BIP5A01120150901011849010345","BizOrderResult":"2009","ResultDesc":"数据发生了错误,请核实!"
SUCC:_BOSSXML.MCN:MMOSReq:Retn=0000,Desc=处理成功,INFO={"MMOSReq":{"OprCode":"06","MSISDN":"13411991736","SPID":"698034","SPServID":"100000","Seq":"0218BIP5A01120150831231225009207","FollowMSISDN":"14715500865","ChrgType":"2","Category":"0","SerialNum":"2","Channel":"04","BizType":"74","EffectiveTime":"20150831231225"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120150831231226019238","TransIDO":"BIP5A01120150831231226019238","TransIDOTime":"20150831231226","MsgSender":"2001"},"MMOSRsp":{"MSISDN":"13411991736","FollowMSISDN":"14715500865","Seq":"0218BIP5A01120150831231225009207","BizOrderResult":"0000","ResultDesc":"业务受理成功"
.......
如上多行, 我想要提取MSISDN  FollowMSISDN  BizOrderResult  ResultDesc
结果如
13822214928 15711728080  0000  业务受理成功
13888545543 15198712767  2009   数据发生了错误,请核实!
13411991736 14715500865  0000   业务受理成功

论坛徽章:
0
2 [报告]
发表于 2015-12-10 22:10 |只看该作者
  1. #-*-coding=utf-8 -*-
  2. import re
  3. abc='''
  4. SUCC:_BOSSXML.MCN:MMOSReq:Retn=0000,Desc=处理成功,INFO=
  5. {"MMOSReq":{"MSISDN":"13822214928","FollowMSISDN":"15711728080","Seq":"0218BIP5A01120151031234446012952","OprCode":"06","BizType":"74","Channel":"70","ChrgType":"2","Category":"0","SerialNum":"1","EffectiveTime":"20151031234446","SPID":"698034","SPServID":"100000"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120151031234447104062","TransIDO":"BIP5A01120151031234447104062","TransIDOTime":"20151031234447","MsgSender":"2001"},"MMOSRsp":{"MSISDN":"13822214928","FollowMSISDN":"15711728080","Seq":"0218BIP5A01120151031234446012952","BizOrderResult":"0000","ResultDesc":"业务受理成功"
  6. ERROR:_BOSSXML.MCN:MMOSReq:Retn=2998,Desc=其他错误,INFO={"MMOSReq":{"OprCode":"06","MSISDN":"13888545543","SPID":"698034","SPServID":"100000","Seq":"0218BIP5A01120150901011849010345","FollowMSISDN":"15198712767","ChrgType":"2","Category":"0","SerialNum":"1","Channel":"70","BizType":"74","EffectiveTime":"20150901011849"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120150901011850021785","TransIDO":"BIP5A01120150901011850021785","TransIDOTime":"20150901011850","MsgSender":"0218"},"MMOSRsp":{"MSISDN":"13888545543","FollowMSISDN":"15198712767","Seq":"0218BIP5A01120150901011849010345","BizOrderResult":"2009","ResultDesc":"数据发生了错误,请核实!"
  7. SUCC:_BOSSXML.MCN:MMOSReq:Retn=0000,Desc=处理成功,INFO={"MMOSReq":{"OprCode":"06","MSISDN":"13411991736","SPID":"698034","SPServID":"100000","Seq":"0218BIP5A01120150831231225009207","FollowMSISDN":"14715500865","ChrgType":"2","Category":"0","SerialNum":"2","Channel":"04","BizType":"74","EffectiveTime":"20150831231225"}}{"_header":{"OrigDomain":"MOSP","SessionID":"SBIP5A01120150831231226019238","TransIDO":"BIP5A01120150831231226019238","TransIDOTime":"20150831231226","MsgSender":"2001"},"MMOSRsp":{"MSISDN":"13411991736","FollowMSISDN":"14715500865","Seq":"0218BIP5A01120150831231225009207","BizOrderResult":"0000","ResultDesc":"业务受理成功"
  8. .......
  9. '''
  10. values=['MSISDN','FollowMSISDN','BizOrderResult','ResultDesc']

  11. for value in values:
  12.         pattern=r'"%s":"\S+?"'%value
  13.         results=re.findall(pattern,abc)
  14.         for result in results:
  15.                 print result.split(':')[1]
复制代码
瞎写了个,前两个有重的不过
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP