본문 바로가기
카테고리 없음

6주차 미션(2/5~2/12) Chapter07(07-2)~08

by 야광비행 2024. 2. 12.

기본 미션

p. 342[직접 해보는 손코딩: BeautifulSoup 스크레이핑 실행하기] 예제 실행 후 결과 화면 캡처하기

from flask import Flask
from urllib import request
from bs4 import BeautifulSoup

app = Flask(__name__)
@app.route("/")

def hello():
   target = request.urlopen('http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108')

   soup = BeautifulSoup(target, 'html.parser')

   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

app.run()

 

 

 

 

 

 

선택 미션

혼공 용어 노트에 나만의 언어로 객체, 클래스, 인스턴스, 생성자, 메소드 정리하고 공유하기

https://hon-gong-pa.tistory.com/23