出力から必要なデータを抽出して変数に保存する方法
これは私のプログラムです:
import commands
cmd = curl -v -k -H "Content-Type: application/json" -X GET -u hitman:hitman <https://test.com:8181/v1/config/sipregistrar
result = commands.getoutput(cmd)
print result
プログラムを実行します:
python test25.py
出力:
About to connect() to test.com port 8181 (#0)
Trying test.com... % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0connected
Connected to 50.50.50.201 (50.50.50.201) port 8181 (#0)
successfully set certificate verify locations:
HTTP/1.1 200 OK
Date: Tue, 05 Jun 2012 18:27:11 GMT
Server: Jetty(6.1.22)
Content-Type: application/json;charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=12buplms5odzt;Path=/config
Transfer-Encoding: chunked
Closing connection #0
SSLv3, TLS alert, Client hello (1):
} [data not shown]
{"sip_domains":{"prefix":[{"name":""}],"domain":[{"name":"k200.com"},{"name":"zinga.com"},{"name":"rambo.com"}]},"sip_security":{"level":2},"sip_trusted_hosts":{"host":[]},"sip_proxy_mode":{"handle_requests":1}}
この出力から、私が必要とするパラメータ:
{"sip_domains":{"prefix":[{"name":""}],"domain":[{"name":"k200.com"},{"name":"zinga.com"}, {"name":"rambo.com"}]},"sip_security":{"level":2},"sip_trusted_hosts":{"host":[]},"sip_proxy_mode":{"handle_requests":1} }
上記を抽出して変数に保存するにはどうすればよいですか?