status.py
963 Bytes
import requests
from bs4 import BeautifulSoup
from datetime import datetime
day_month = datetime.today().month
day_day = datetime.today().day
data = []
url='https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EC%BD%94%EB%A1%9C%EB%82%98+%ED%98%84%ED%99%A9'
hdr = {'Accept-Language': 'ko_KR,en;q=0.8', 'User-Agent': ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36')}
req = requests.get(url, headers=hdr)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
for i in soup.select('div[class=state_graph]'):
data.append(i.text)
datasets = data[0]
datasets = datasets.split(" ",10)
datasets = datasets[1:]
datasets = datasets[:-1]
for i in range(0,4):
datasets[i] = datasets[i].replace(" ","")
# insert into text file
date = f"{day_month}월 {day_day}일"
f = open("status.txt", 'w')
f.write(date + "\n")
for i in datasets:
f.write(i + "\n")
f.close()