Re: [問題] SOAP字串轉換

看板Python作者 (new life)時間16年前 (2009/07/30 20:47), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《giveatry (new life)》之銘言: : 標題: [問題] SOAP字串轉換 : 時間: Thu Jul 30 17:32:43 2009 : : 請問一下,我從網路抓到一個SOAP封包的內容,長的像這樣: : a=" : &lt;DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp= : "urn:schemas-upnp-org:metadata-1-0/upnp/"xmlns:dlna="urn:schemas-dlna- : org:metadata-1-0/" xmlns:pv="http://www.pv.com/pvns/" xmlns="urn:schem : as-upnp-org:metadata-1-0/DIDL-Lite/"&gt;&lt;/DIDL-Lite&gt;" : : 請問一下我要怎麼把&lt;轉成< ? : : 我試過re.sub("&lt;", "<", a) : 可是不work : 不知是哪裡搞錯了? : 謝謝 : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 116.59.137.173 : 推 twolights:不 work 是怎樣不 work? 我這邊試的結果是正常的 07/30 19:17 : → twolights:另外如果只是單純地要置換字串可以用... 07/30 19:17 : → twolights:a.replace('&lt;', '<') 07/30 19:18 我的code主要的部份是這樣: conn = httplib.HTTPConnection(domainName) conn.request("POST", parameter, request, headers) HTR = conn.getresponse() content = HTR.read() conn.close() #以上是直接去某個server抓資料 #re.sub("&lt;", "<", content) #抓來的資料就是我上面po的,但是要代換就不work content.replace('&lt;', '<') print content 其實我在console下,自己手動輸入一個字串做代換的話,是work的 但是從server抓資料後(就是上面的content)直接做代換,怎樣都不work 應該是哪個環節出了問題但是我不清楚 想了很久都想不出為什麼不work -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.120.32.206

07/30 20:50, , 1F
因為要用 content = content.replace('%lt;', '<')
07/30 20:50, 1F

07/30 20:57, , 2F
啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~我耍笨了,別轉笨版啊
07/30 20:57, 2F
文章代碼(AID): #1ASPPtDt (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1ASPPtDt (Python)