python - github code search api returns html instead of json -
i want data github api through python:
import requests headers = {'user-agent': 'awesome-octocat-app', 'accept': 'application/vnd.github.preview+json'} link = "https://github.com/search?q=chembl+created:>=2000" r = requests.get(link, headers=headers)
and looks went fine:
r.ok >>> true
so expect have json in response:
r.json()
but throws exception:
jsondecodeerror: no json object decoded: line 1 column 0 (char 0)
unfortunately have html:
r.content <!doctype html> <html> <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#"> <meta charset='utf-8'> <meta http-equiv="x-ua-compatible" content="ie=edge"> ...
this html contains repositories i'm looking need json not html. why?
you need use actual api json content. http://github.com/search
regular html frontend. wanted search repositories:
import requests headers = {'user-agent': 'awesome-octocat-app', 'accept': 'application/vnd.github.preview+json'} link = "https://api.github.com/search/repositories" query = {'q': 'chembl created:>=2000'} r = requests.get(link, headers=headers, params=query)
this gives me:
>>> r = requests.get(link, headers=headers, params=query) >>> r.ok true >>> r.json().keys() [u'total_count', u'items'] >>> r.json()['total_count'] 17
Comments
Post a Comment