', '\n') element = element.replace('
import requests
import datetime
from bs4 import BeautifulSoup
import re
dt = datetime.datetime.now()
def get_html(url):
_html = ""
resp = requests.get(url)
if resp.status_code == 200:
_html = resp.text
return _html
def get_diet(ymd):
schYmd = ymd #str
num = dt.weekday() + 1
URL = (
"<https://stu.sen.go.kr/sts_sci_md01_001.do?domainCode=B10&schulCode=B100000658&schulCrseScCode=4&schulKndScCode=04&schMmealScCode=2&schYmd=%s>" % (schYmd)
)
html = get_html(URL)
soup = BeautifulSoup(html, 'html.parser')
element = soup.find_all("tr")
element = element[2].find_all('td')
try:
element = element[num]
element = str(element)
element = element.replace('[', '')
element = element.replace(']', '')
element = element.replace('<br/>', '\\n')
element = element.replace('<td class="textC last">', '')
element = element.replace('<td class="textC">', '')
element = element.replace('</td>', '')
element = element.replace('(h)', '')
element = element.replace('.', '')
element = re.sub(r"\\d", "", element)
except:
element = " "
return element
a = get_diet(dt.strftime('%Y.%m.%d'))
print(a)