혼공파 6주차 미션

기본미션: 342쪽의 [직접 해보는 손코딩:BeautifulSoup 스크레이핑 실행하기] 예제 실행 후 결과 화면 인증샷

Error: Could not locate a Flask application. You did not
provide the "FLASK_APP" environment variable, and a
"wsgi.py" or "app.py" module was not found in the current directory.

오류때문에 오전 내내 애먼 flask와 BeautifulSoup 붙잡고 설치-삭제-설치-업데이트 무한반복. 해결하긴 했지만 추가적인 공부가 필요할 것으로 보임

# 모듈을 읽어 들입니다.
from flask import Flask
from urllib import request
from bs4 import BeautifulSoup

# 웹 서버를 생성합니다.
app = Flask(__name__)
@app.route("/")

def hello():
    # urlopen() 함수로 기상청의 전국 날씨를 읽습니다.
    target = request.urlopen("http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108")

    # BeautifulSoup를 사용해 웹 페이지를 분석합니다.
    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

선택미션: 혼공 용어 노트에 나만의 언어로 객체, 클래스, 인스턴스, 생성자, 메소드 보충 설명쓰고 인증샷

객체: 속성을 가질 수 있는 모든 것

클래스: 객체의 설계도
같은 특성을 지닌 범위. 카테고리라고 볼 수 있음

인스턴스: 클래스를 기반으로 만들어진 객체
클래스 내에서 어떠한 것을 특정지어 말할 때 인스턴스라고 함

메소드: 클래스 내부에 정의된 함수
파이썬 내에서는 주로 함수나 인스턴스 함수, 멤버 함수 등으로 불림
선언할 때 첫 번째 매개변수로 self를 넣어야 함

좋은 웹페이지 즐겨찾기