Created
May 5, 2016 18:29
-
-
Save devStepsize/e0c5c516463c229f94479a439e234227 to your computer and use it in GitHub Desktop.
Get identified keywords from a webpage using AlchemyAPI
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
import requests | |
endpoint = "http://gateway-a.watsonplatform.net/calls/url/URLGetRankedKeywords" | |
parameters = { | |
'apikey': API_KEY, | |
'outputMode': 'json', | |
'url': 'https://blog.vellumatlanta.com/2016/05/04/apple-stole-my-music-no-seriously/' | |
} | |
r = requests.get(endpoint, params=parameters) | |
if r.status_code == 200: | |
resp = r.json() | |
# Print keywords | |
# Keywords are already ranked by relevance, high -> low | |
keywords = [(kw['text'], kw['relevance']) for kw in resp.get('keywords')] | |
# Print top 3 most relevant | |
print keywords[:3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment