; 타인이 만들어 배포한 External Module
pip; 파이썬 패키지 관리 시스템. 특정 버전의 모듈 설치/제거 기능 지원
; 파이썬의 웹 페이지 분석 모듈
cmd에서 모듈 설치하려니까 안돼서 터미널에서 설치함
PS C:\python> pip install beautifulsoup4
; 웹 개발 프레임워크
PS C:\python> pip install Flask
마찬가지로 터미널에서 설치
flask 코드 실행
$env:FLASK_APP="파일 이름"
flask run
터미널 종료시 ctrl+c
#beautiful_flask.py
# 모듈 읽어 들이기
from flask import Flask
from urllib import request
from bs4 import BeautifulSoup
# web server
app = Flask(__name__)
@app.route("/")
def hello():
#함수로 전국 날씨 읽기
target = request.urlopen("http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108")
#web page analyze
soup = BeautifulSoup(target, "html.parser")
#location
output = ""
for location in soup.select("location"):
output += "<h3>{}</h3>".format(location.select_one("city").string)
output += "날씨: {}<br/>".format(location.select_one("wf").string)
output += "최저/최고 기온: {}/{}"\
.format(\
location.select_one("tmn").string,\
location.select_one("tmx").string\
)
output += "<hr/>"
return output