Skip to content

Instantly share code, notes, and snippets.

@cyco130
Last active April 8, 2020 06:51
Show Gist options
  • Save cyco130/b90f5423ca3e1417bda0b5aff66bedf7 to your computer and use it in GitHub Desktop.
Save cyco130/b90f5423ca3e1417bda0b5aff66bedf7 to your computer and use it in GitHub Desktop.
// Modern bir tarayıcıda https://www.turkiye.gov.tr/istanbul-buyuksehir-belediyesi-vefat-sorgulama
// adresine gidip bu kodu developer console'a yapıştırarak çalıştırabilirsiniz.
(function() {
async function send(url, date) {
let fd = new FormData();
fd.append("tarih", date);
fd.append("token", document.body.dataset.token);
fd.append("btn", "Sorgula");
const resp = await fetch(url, {
method: "POST",
credentials: "include",
body: fd
});
const text = await resp.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
return doc.querySelectorAll(".resultTable > tbody > tr").length;
}
async function go() {
let start = new Date("2000-01-01");
let date = new Date();
document.head.innerHTML += `<style>tr > * {padding: 3px; border: solid 1px black; text-align: right} body {padding: 10px}</style>`
document.body.innerHTML = "<table><thead><th>Tarih</th><th>Ölüm</th></thead><tbody></tbody></table>";
const tbody = document.querySelector("tbody");
while (date >= start) {
const year = date.getFullYear().toString().padStart(4, "0");
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = (date.getDate()).toString().padStart(2, "0");
const asStr = `${day}/${month}/${year}`;
const result = await send("https://www.turkiye.gov.tr/istanbul-buyuksehir-belediyesi-vefat-sorgulama?submit", asStr);
const tr = document.createElement("tr");
tr.innerHTML = `<tr><td>${month}/${day}/${year}</td><td>${result}</td></tr>`;
tbody.append(tr);
date.setDate(date.getDate()-1);
}
}
go();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment