Skip to content

Instantly share code, notes, and snippets.

@tnraro
Created January 2, 2023 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnraro/01b3380037cf1574d9b914a857d05ba9 to your computer and use it in GitHub Desktop.
Save tnraro/01b3380037cf1574d9b914a857d05ba9 to your computer and use it in GitHub Desktop.
// https://www.weather.go.kr/w/obs-climate/land/past-obs/obs-by-day.do?stn=143
{
const year = document.querySelector("[name=yy]").value;
const month = Number(document.querySelector("[name=mm]").value);
const startDay = 10;
const endDay = 19;
const d = new Date(year, month-1, 1);
const offset = d.getDay();
const p = x => {
const o = {};
for (const m of x.matchAll(/(평균|최고|최저)기온:(-?\d+\.\d+)(?=℃)/g)) {
o[m[1]] = Number(m[2]);
}
return o;
};
`${year}\t${month}\t` + [...document.querySelectorAll(".table-cal tr:nth-child(2n)>td")].slice(offset).slice(startDay-1, endDay).filter(x => x.textContent.trim().length !== 0).map(x => p(x.outerText)).map((x, i) => `${x["평균"]}\t${x["최고"]}\t${x["최저"]}`).join("\t");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment