-1

I get the following from a url (get requests with python module request):

{"AMU":"PAR","nombres":"158612","id":"stacks"}

How would I get python to print just the values for example, I want it to print "stacks" or "158612"

I have tried:

soup.find['id']

and:

soup.find("AMU": "PAR")["nombres"]
PythonNLMB
  • 41
  • 1
  • 9

1 Answers1

3

This is JSON. You can convert it to a normal python dict using json.loads(string), or in the case of requests there's a .json() shortcut:

data = requests.get(url).json()
nombres = data['nombres']
Alex Hall
  • 31,431
  • 4
  • 39
  • 71
  • Getting this error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) – PythonNLMB Dec 24 '16 at 15:57
  • @PythonNLMB sounds like what you're getting with `requests` isn't what you showed us. Can you share the URL? If not, what if you `print(repr(requests.get(url).text))`? – Alex Hall Dec 24 '16 at 16:02