Created
November 21, 2016 18:00
-
-
Save b-meson/869fbf6a32edbb4029f2e13f60f11c15 to your computer and use it in GitHub Desktop.
OpenOversight II scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SAMPLE JSON FROM THE II SCRAPER USING THIS URL http://staging.cpdp.co/api/v1/suggestion/?text=Loga | |
### | |
### {u'NEIGHBORHOODS': [{u'text': u'Logan Square', u'score': 1.0, u'payload': {u'url': u'not implemented', | |
### u'result_text': u'Logan Square'}}], u'OFFICER': [{u'text': u'Alexus Logan', u'score': 1.0, u'payload': | |
### {u'url': u'https://cpdb.co/officer/alexus-logan/4264', u'result_text': u'Alexus Logan', u'result_extra_information': | |
### u'Badge 6585'}}, {u'text': u'Logan Westcott', u'score': 1.0, u'payload': {u'url': u' | |
### https://cpdb.co/officer/logan-westcott/7989', u'result_text': u'Logan Westcott', u'result_extra_information': u' | |
### Badge 13487'}}, {u'text': u'Michael Logan', u'score': 1.0, u'payload': {u'url': u' | |
### https://cpdb.co/officer/michael-logan/21496', u'result_text': u'Michael Logan', u'result_extra_information': u''}}, | |
### {u'text': u'Nekeeta Logan', u'score': 1.0, u'payload': {u'url': u'https://cpdb.co/officer/nekeeta-logan/4265', u' | |
### result_text': u'Nekeeta Logan', u'result_extra_information': u'Badge 11907'}}, {u'text': u'Patrick Logan', u'score': | |
### 1.0, u'payload': {u'url': u'https://cpdb.co/officer/patrick-logan/21497', u'result_text': u'Patrick Logan', | |
### u'result_extra_information': u'Badge 500'}}, {u'text': u'Robert Logay', u'score': 1.0, u'payload': {u'url': u' | |
### https://cpdb.co/officer/robert-logay/21498', u'result_text': u'Robert Logay', u'result_extra_information': u' | |
### Badge 13803'}}], u'UNIT': []} | |
>>> from urllib2 import Request, urlopen, json | |
>>> headers = { 'Content-Type': 'application/json' } | |
>>> request = Request("http://staging.cpdp.co/api/v1/suggestion/?"+assignment.star_no, headers=headers) | |
>>> response_body = urlopen(request) | |
>>> data=json.load(response_body) | |
>>> data.get('OFFICER') | |
>>> for item in data: | |
print item['payload']['url'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reply: