Skip to content

Instantly share code, notes, and snippets.

@jaturken
Last active February 3, 2019 20:27
Show Gist options
  • Save jaturken/4c3efd647f9981d0373bd36eef9cd4dc to your computer and use it in GitHub Desktop.
Save jaturken/4c3efd647f9981d0373bd36eef9cd4dc to your computer and use it in GitHub Desktop.
var source_url = "http://maismedicos.saude.gov.br/new/web/app.php/selecao-municipio/selecionar"
const returnedBack = async (url) => { return await fetch(url).then(response => (document.URL == response.url)) }
i = 0;
keep_on_trying = true;
while (keep_on_trying) {
if (await returnedBack(source_url)) {
i += 1;
console.log(`[${i}]Still not available, retry`);
} else {
console.log("!!!SUCCESS!!!");
console.log("Tente abrir a selecionar página");
var aTags = document.getElementsByTagName("a");
var found;
for (var i = 0; i < aTags.length; i++) {
if (aTags[i].textContent == "Selecionar") {
found = aTags[i];
break;
}
}
found.click();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment