Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Created May 5, 2016 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devStepsize/e0c5c516463c229f94479a439e234227 to your computer and use it in GitHub Desktop.
Save devStepsize/e0c5c516463c229f94479a439e234227 to your computer and use it in GitHub Desktop.
Get identified keywords from a webpage using AlchemyAPI
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