Showing
1 changed file
with
36 additions
and
0 deletions
weather_chat.py
0 → 100644
| 1 | +import requests | ||
| 2 | +from bs4 import BeautifulSoup | ||
| 3 | +from pprint import pprint | ||
| 4 | + | ||
| 5 | +html = requests.get('https://search.naver.com/search.naver?query=날씨') | ||
| 6 | +soup = BeautifulSoup(html.text, 'html.parser') | ||
| 7 | + | ||
| 8 | +data1 = soup.find('div', {'class': 'weather_box'}) | ||
| 9 | + | ||
| 10 | +address = data1.find('span', {'class': 'btn_select'}).text | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +find_weather= data1.find('p', {'class': 'cast_txt'}).text | ||
| 14 | + | ||
| 15 | +weather_endIndex = 0 | ||
| 16 | + | ||
| 17 | +for i in range(0,len(find_weather)): | ||
| 18 | + if find_weather[i] == ',': | ||
| 19 | + weather_endIndex = i | ||
| 20 | + break | ||
| 21 | + | ||
| 22 | +weather = find_weather[0:weather_endIndex] | ||
| 23 | + | ||
| 24 | +notice = "" | ||
| 25 | +if '비' in weather: | ||
| 26 | + notice = "비가 올 가능성이 있습니다. 우산을 챙기세요." | ||
| 27 | +elif '눈' in weather: | ||
| 28 | + notice = "눈이 올 가능성이 있습니다. 방한 용품을 챙기세요." | ||
| 29 | +else: | ||
| 30 | + notice = "특이사항이 없습니다." | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | +find_currenttemp = data1.find('span', {'class':'todaytemp'}).text | ||
| 35 | +currentTemp = int(find_currenttemp) | ||
| 36 | +print('현재 온도: '+find_currenttemp+'도') | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment