I'm writing a program using newsapi and wx to get headlines related to certain topics upon demand.
However, the function outputs a block of text like such (if searching for the word 'Tesla'):
{'status': 'ok', 'totalResults': 14, 'articles': [{'source': {'id': 'techcrunch', 'name': 'TechCrunch'}, 'author': 'Darrell Etherington', 'title': "Tesla focuses on service with 25 new service centers in Q2, rate of new openings to 'increase'", 'description': 'Tesla is set to ramp up the rate at which it opens new service facilities aggressively, according to CEO Elon Musk’s guidance on the company’s Q2 2019 earnings call. In total, Tesla opened 25 new service centers during the quarter, and added 100 new service v…', 'url': 'https://techcrunch.com/2019/07/24/tesla-focuses-on-service-with-25-new-service-centers-in-q2-rate-of-new-openings-to-increase/', 'urlToImage': 'https://techcrunch.com/wp-content/uploads/2019/07/GettyImages-1150569888.jpg?w=592', 'publishedAt': '2019-07-24T23:36:47Z', 'content': 'Tesla is set to ramp up the rate at which it opens new service facilities aggressively, according to CEO Elon Musk’s guidance on the company’s Q2 2019 earnings call. In total, Tesla opened 25 new service centers during the quarter, and added 100 new service v… [+2866 chars]'}, {'source': {'id': 'the-verge', 'name': 'The Verge'}, 'author': "Sean O'Kane", 'title': 'Tesla’s longtime CTO is stepping down', 'description': 'Lon.....
I want to get all of the titles to display in a list so I don't have to parse through this massive chunk of text.
My thought is to search for all occurrences of 'title': and then print each phrase that is in the quotes after each occurrence. Any recommendations?
Note: The code that generates this text is:
def NewsSearch(self, event):
newsapi = NewsApiClient(api_key='8ab524f489d34b278ad537389c789498')
input = self.tc4.GetValue()
top_headlines = newsapi.get_top_headlines(q=input)
print(top_headlines)
where the input is gathered from a TextCtrl panel in wx, and the function is called by binding a button click to the function.