I've scraped a webpage using an API and want to access one part of the results, but am having difficulty accessing it:
import requests
import json
headers = {'x-api-key': 'my_key'}
test_url= "https://api.propublica.org/congress/v1/statements/date/2018-05-
22.json"
resp = requests.get(test_url, headers=headers).json()
The results are coming out in a dictionary format that looks like this:
[{'chamber': 'Senate',
'congress': 115,
'party': 'R',
'state': 'NC',
'url': 'url1_goes_here'},
{'chamber': 'Senate',
'congress': 115,
'party': 'R',
'state': 'ND',
'url': 'url2_goes_here'}]
I want to extract the 'url' value from each entry, but the entries doesn't seem to have a key by which I can drill down. How can I go about accessing these? I thought that:
resp["url]
Would work, but I didn't have any luck. The output I'd ideally want would be something like:
[url1, url2]
{'message': None}for me so there will obviously an error when you try to geturlwhich isn't there. The site also shows you need an api key so if you haven't one you need to sign up to get your actual data from the api