Last active
February 3, 2019 20:27
-
-
Save jaturken/4c3efd647f9981d0373bd36eef9cd4dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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