2016-03-02 205 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]