IT/컴퓨터프로그램

[Python] 구글 트렌드(Google Trends PYTHON API)

chn1002 2022. 5. 16. 09:02

[Python] 구글 트렌드(Google Trends PYTHON API)

Google Trend 에 연결하기

pip 를 이용해 pytrends library 를 받는다.

pip install pytrends

Google Trend Python 을 import 하여 사용

TrendReq 의 매개변수

  • host language(hl) = "ko"
  • Timezone(tz) = 360 

pytrends.build_payload 의 매개변수

  • keyword: 데이터를 가져올 키워드 목록(한번에 5개 키워드로 제한)
  • geo: 지리적 위치
  • timeframe: 관심있는 시간 프레임
    keywords=["코로나"]
    
    pytrends = TrendReq(hl="ko", tz=360)
    pytrends.build_payload(keywords, cat=0, timeframe="today 5-y", geo="KR", gprop="")
    getdatainfo = pytrends.interest_over_time()
    print(getdatainfo)
    
    getdatainfo.to_csv(csvPath, encoding="utf-8")