2016-03-02 206 views
0

我认为这很简单.....Python:SOAP响应。删除响应标题,保留其余部分?

我有一个脚本,需要一堆数据,更改一些字符,将数据拆分为包含标题和输出为CSV的列和行。这在使用从文本文件进入的数据进行测试时效果很好。真正的用途是调用一个认证的Web服务。这也很好。

问题是格式化数据的所有代码,并且在从webservice调用最终的CSV文件时不起作用。

原因是结果

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns1:GetACustomReportResponse xmlns:ns1="http://www.customurlfortesting.com/gem/services/gds"><report>Header1,Header2,Header3 

的第一行。当我最初的测试,我只是取回头1,头2,Header3等全部由一个字符分隔那更换。现在同样如此,但由于Header1之前的内容,其余格式化在开始时都失败了。有没有办法简单地在结果中获取这些信息?

r = requests.post(url,data=body,headers=headers) 
data = str(r.text.encode('utf-8').replace("\"....etc < im guessing I can strip that first line of the reults in here since this is where my results are but I don't exactly how to remove that line dynamically without affecting anything else. I want to remove everything from <env:Envelope to <report> including <env:Envelope and <report> 

感谢

+0

问题不是很清楚,你能具体问题展开?您是使用特定的SOAP库还是仅使用'requests'模块? – Cahit

+0

@Cahit在原文中增加了一些细节。让我知道如果它仍然不清楚。谢谢 –

回答

0

得到它排序

添加到初始列定义

.rpartition('<report>')[-1]