Skip to content

Instantly share code, notes, and snippets.

@jiyeonseo
Last active September 2, 2020 02:11
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 jiyeonseo/bdd325425ed608e60782a453763bf7ad to your computer and use it in GitHub Desktop.
Save jiyeonseo/bdd325425ed608e60782a453763bf7ad to your computer and use it in GitHub Desktop.
kakao local api
import requests
import sys
'''
$ python kakao_local_api.py {query}
'''
# curl -v -X GET "https://dapi.kakao.com/v2/local/search/keyword.json?category_group_code=BK9&page=2" \
# --data-urlencode "query=카카오" \
# -H "Authorization: KakaoAK kkkkk"
KAKAO_LOCAL_BASE_URL = 'https://dapi.kakao.com/v2/local/search/keyword.json?'
def get_header():
return {
'Authorization': 'KakaoAK kkkkkkkk'
}
def main(query: str):
assert query
is_end = False
page = 1
while is_end == False:
query_url = f"{KAKAO_LOCAL_BASE_URL}&page={page}&query={query}"
print(query_url)
res = requests.get(query_url, headers=get_header())
meta = res.json().get("meta")
results = res.json().get("documents")
print("page ", page , " : ", len(results), "/", meta.get("total_count"))
is_end = meta.get("is_end")
page += 1
if __name__ == "__main__":
argv = sys.argv
q = argv[1]
print(f'Query={q}')
result = main(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment