[python] 백과사전
2020. 12. 29. 20:34ㆍHi/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는 프로그램 실행 시 바로 종료되지 않게 추가하였습니다.
기본 베이스는 네이버 백과사전입니다.
728x90
'Hi > Python' 카테고리의 다른 글
[Python] 똥피하기_ 고전게임 제작 (0) | 2021.01.09 |
---|---|
[Python] 인스타 크롤링 / 이미지다운 (2) | 2021.01.05 |
[python] 카카오톡 테러(매크로) 프로그램 만들기 (3) | 2020.12.29 |