food_update.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | # -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup import datetime #요일설정 dt = datetime.datetime.now() if dt.hour > 17: today = '%02d.%02d'%(dt.month,dt.day+1) else: today = '%02d.%02d'%(dt.month,dt.day) print("[ === "+today + " 식단 === ]") #html 요청 url = 'http://www.kyonggi.ac.kr/webRestMenu.kgu?mzcode=K00M04038500&restGb=suwon' res = requests.get(url) html = res.text #soup 설정 soup = BeautifulSoup(html,'lxml') base = soup.find_all('tbody',{'class' : 'text_center'}) #E-스퀘어 print("_______E-스퀘어_______") e = base[0].find_all('tr') for i in [0,5,10,15,20]: if today in e[i].get_text(): break for j in range(5): td = e[i+j].find_all('td') if td[1].string == " ": continue print("\n["+td[0].get_text().encode('utf-8')[:6]+"]") for k in td[1].string.encode('utf-8').split('|'): print(k) print("\n_______감성코어_______") #감성코어 g = base[1].find_all('tr') for i in [0,4,8,12,18]: if today in g[i].get_text(): break td = g[i].find_all('td') if td[1].string != " ": print("\n[味소반]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') for i in fd: print(" "+i) td = g[1].find_all('td') if td[1].string != " ": print("\n[the bob]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') for i in fd: print(" "+i) td = g[2].find_all('td') if td[1].string != " ": print("\n[덮밥]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') for i in fd: print(" "+i) td = g[3].find_all('td') if td[1].string != " ": print("\n[worldish]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') if fd[0] == '': del fd[0] for i in fd: print(" "+i) #교직원 주간메뉴 print("\n______교직원식당______") t = base[2].find_all('tr') for i in [0,2,4,6,8]: if today in t[i].get_text(): break td = t[i].find_all('td') if td[1].string != " ": print("\n[중식]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') for i in fd: print(" "+i) td = t[1].find_all('td') if td[1].string != " ": print("\n[service-bar]") fd = td[1].string.encode('utf-8').replace(" ",'').split('|') for i in fd: print(" "+i) | cs |