python文本解析_python – 优雅的结构化文本文件解析

我需要解析实时聊天对话的抄本。我第一次看到这个文件的想法是抛出正则表达式的问题,但我想知道人们使用了什么其他方法。

我把这个标题放在了优雅的位置,我以前发现这种类型的任务有一个很难保持只是依赖于正则表达式的危险。

成绩单由www.providesupport.com生成,并通过电子邮件发送到一个帐户,然后从电子邮件中提取一个纯文本的附件。

解析文件的原因是提取会话文本以供稍后,但也可以识别访问者和运算符名称,以便可以通过CRM提供信息。

这是一个抄本文件的例子:

Chat Transcript

Visitor: Random Website Visitor

Operator: Milton

Company: Initech

Started: 16 Oct 2008 9:13:58

Finished: 16 Oct 2008 9:45:44

Random Website Visitor: Where do i get the cover sheet for the TPS report?

* There are no operators available at the moment. If you would like to leave a message, please type it in the input field below and click "Send" button

* Call accepted by operator Milton. Currently in room: Milton, Random Website Visitor.

Milton: Y-- Excuse me. You-- I believe you have my stapler?

Random Website Visitor: I really just need the cover sheet, okay?

Milton: it's not okay because if they take my stapler then I'll, I'll, I'll set the building on fire...

Random Website Visitor: oh i found it, thanks anyway.

* Random Website Visitor is now off-line and may not reply. Currently in room: Milton.

Milton: Well, Ok. But… that's the last straw.

* Milton has left the conversation. Currently in room: room is empty.

Visitor Details

---------------

Your Name: Random Website Visitor

Your Question: Where do i get the cover sheet for the TPS report?

IP Address: 255.255.255.255

Host Name: 255.255.255.255

Referrer: Unknown

Browser/OS: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值