I am using twython to connect to Twitter API and retrieve a query. Here is an example of what I get:
---START----
{u'next_page': u'?page=2&max_id=215397707'
....
: 215397707794219008L, u'page': 1}
----END----
What I am interested in is the actual tweet which starts like this:
u'text': u'@ilariargn devi fare un corso sul respiro! Sarebbero 7686879 euro, ci vieni? #perderetempo', u'from_user_name':
So everything between “u’text’: u'” and “u’from_user_name'”. I tried to get this information first with key and value because it is a dictionary. Does not work. Then I tried to convert the dictionary into a list and use a string search to get the position. Does not work either. How do I get this information?
I tried suggested solutions and received following messages:
tweet = json.loads(results)[u'text']
File "C:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
And for the second solution – if I write [t’text] I get a syntax error:
tweet = results[u'text']
KeyError: u'text'
Ok. After some trials I found the following solution to access the actual tweets: