使用python将响应数据捕获到数组中

时间:2016-08-02 09:15:16

标签: python python-2.7

使用python:

将响应数据捕获到数组中

当我使用urlib2读取网址时,我使用print resp在控制台中获得以下响应

code : resp = urllib2.urlopen(memberProfileInfo).read()

Console display 
OCODE: 11
UCODE: XXX
GID: XXXXXX
GDISP: XXXXX
\# rc=0, count=1, message=Success

如何使用python 2.7将这些ocode等值捕获到数组中?

1 个答案:

答案 0 :(得分:0)

I did this and it worked:
Code as below:
profdata = []
resp = urllib2.urlopen(memberProfileInfo).read()
profdata = resp.split('\n')
return profdata

However now in the excel I get all the response appended:
OCODE: 11 UCODE: XXX GID: XXXXXX GDISP: XXXXX \# rc=0, count=1, message=Success

Can we use regex and only capture data after : ? any suggestions here for the rest of the capture.