-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"] 
2
  • If it's just a dict, do x['nombres'] or x['id'] Commented Dec 24, 2016 at 15:19
  • You don't need beautifulsoup for that, convert it to python's dict with the json built-in library. then you can iterate over the dict. Commented Dec 24, 2016 at 15:19

1 Answer 1

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'] 
Sign up to request clarification or add additional context in comments.

2 Comments

Getting this error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@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))?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.