-
Anonymous
Запросы Python: получение атрибутов из возвращенной строки JSON
Сообщение
Anonymous »
Код: Выделить всё
import requests
r = requests.get('http://httpbin.org/get');
r.text
возвращает:
Код: Выделить всё
u'{\n "url": "http://httpbin.org/get",\n "headers": {\n "Host": "httpbin.org",\n "Accept-Encoding": "gzip, deflate, compress",\n "Connection": "close",\n "Accept": "*/*",\n "User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7",\n "X-Request-Id": "db302999-d07f-4dd6-8c1e-14db45d39fb0"\n },\n "origin": "61.228.172.190",\n "args": {}\n}'
Как получить значения происхождения и заголовков/хоста?
Подробнее здесь:
https://stackoverflow.com/questions/232 ... son-string
1733929288
Anonymous
[code]import requests
r = requests.get('http://httpbin.org/get');
r.text
[/code]
возвращает:
[code]u'{\n "url": "http://httpbin.org/get",\n "headers": {\n "Host": "httpbin.org",\n "Accept-Encoding": "gzip, deflate, compress",\n "Connection": "close",\n "Accept": "*/*",\n "User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7",\n "X-Request-Id": "db302999-d07f-4dd6-8c1e-14db45d39fb0"\n },\n "origin": "61.228.172.190",\n "args": {}\n}'
[/code]
Как получить значения происхождения и заголовков/хоста?
Подробнее здесь: [url]https://stackoverflow.com/questions/23231869/python-requests-get-attributes-from-returned-json-string[/url]