[python] 백과사전

2020. 12. 29. 20:34Hi/Python

전체코드는 아래와 같습니다.

import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
import os

baseURL = 'https://dict.naver.com/search.nhn?dicQuery='   #네이버백과사전링크

while True :
    inputURL = input('검색할 단어 : ')
    if inputURL == '그만' : break
    mixURL = baseURL + urllib.parse.quote_plus(inputURL) #한글로 쓰면 아스키코드로 자동 변환
    html = urllib.request.urlopen(mixURL).read() #url링크 가져와서 읽음
    soup = BeautifulSoup(html, 'html.parser')
    bsSoup = soup.find("dd") 
    print(bsSoup.text)

os.system('pause')

크롤링을 공부하고 단어를 입력하면 뜻이 나오는 백과사전 프로그램을 만들었습니다.

os는 프로그램 실행 시 바로 종료되지 않게  추가하였습니다.

기본 베이스는 네이버 백과사전입니다.

 

네이버 백과사전에 들어가서 개발자 모드로 뜻이 저장되어있는 해당 태그를 찾는다.  

 

응용프로그램은 pyinstaller를 이용해 만들었다. 영어든 한글이든 쓰면 곧바로 뜻이 나온다. 
백과사전.exe
6.64MB

728x90