-
[Python] python 으로 네이버 검색어 조회Languague/Python 2020. 5. 19. 16:02
사전작업
- 파이썬 설치
- pip 설치
- http 요청에 필요한 라이브러리 python requests 라이브러리 설치
pip install requests
검색어 파싱하기
원래는 html 파일 파싱하려고 했으나
2020 5월 19일 기준 네이버 검색어는 api 로 조회하고 있어, 크롬 네트워크 탭에서 api 주소 확인 후 소스코드에 복붙하고 json 데이터 파싱import requests # from bs4 import BeautifulSoup import json response = requests.get('https://apis.naver.com/mobile_main/srchrank/srchrank?frm=main&ag=30s&gr=2&ma=0&si=0&en=0&sp=0') html = response.text # soup = BeautifulSoup(html, "html.parser") json_dict = json.loads(html) for i in json_dict['data']: print(i['keyword'])
다음과 같이 소스 파일 작성한 후
python 실행!!python 파일명.py
반응형'Languague > Python' 카테고리의 다른 글
[Python] 파이썬 Non-ASCII character 오류(파이썬 한글 인코딩) (0) 2020.09.29 [Python] pip 설치 (0) 2020.05.19