RSS 서비스 → 전국 중기예보 RSS 주소 가져오기
1
from urllib import request
from bs4 import BeautifulSoup
# RSS 주소 입력
target = request.urlopen("<http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108>")
print(target)
from urllib import request
from bs4 import BeautifulSoup
# RSS 주소 입력
target = request.urlopen("<http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108>")
# 파싱
soup = BeautifulSoup(target, "html.parser")
for location in soup.select("location") :
print(location.select_one("city").string) #location 안에 내용을 문자열로
from urllib import request
from bs4 import BeautifulSoup
# RSS 주소 입력
target = request.urlopen("<http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=108>")
# 파싱
soup = BeautifulSoup(target, "html.parser")
for location in soup.select("location") :
print("도시: ", location.select_one("city").string) #location 안에 내용을 문자열로
print("날씨: ", location.select_one("wf").string)
print("최저기온: ", location.select_one("tmn").string)
print("최고기온: ", location.select_one("tmx").string)
print("강수확률: ", location.select_one("rnSt").string)
print("==================")