0

I bust my head but can not sort this out.

numbers, names are fictional. but the idea is like this

I read a link like 'https://graph.facebook.com/123'

this results to source code:

{
   "id": "123",
   "name": "John Doe",
   "first_name": "John",
   "last_name": "Doe",
   "link": "http://www.facebook.com/people/John-Doe/123",
   "gender": "male",
   "locale": "en_US"
}

i want to extract all the information of id, name ,etc.

I try this but it fails

    link = 'https://graph.facebook.com/123'
    result = browser.open(link)
    text = result.read()
    result.close()
    id = re.search('"id": "(.*?)",', cont)

regex '"id": "(.*?)",' seems to be correct, but nothind is returned.. Why???

1 Answer 1

7

That seems JSON, you don't want to use regex to parse that.

link = 'https://graph.facebook.com/123'
result = browser.open(link)
data = json.load(result)
print data['id']
Sign up to request clarification or add additional context in comments.

1 Comment

@user492741, you should click on the checkmark to the side of the answer then to accept it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.