--> secure.vd.ch/territoire/intercapi/publication/pages/auskunft/publikationen/search_direct.xhtml
--| 10 May 2020
tell application "Safari"
activate
set datumVonTag to 1
set datumVonMonat to 1
set datumVonJahr to do JavaScript "document.getElementById('capwebSearchForm:datumVonJahr').value" in document 1
set datumBisTag to 1
set datumBisMonat to datumVonMonat + 2
set datumBisJahr to do JavaScript "document.getElementById('capwebSearchForm:datumBisJahr').value" in document 1
set lastYear to datumBisJahr
set datumBisJahr to datumVonJahr
repeat while datumVonJahr is less than or equal to lastYear
do JavaScript "document.getElementById('capwebSearchForm:datumVonTag').value =" & datumVonTag as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:datumVonMonat').value =" & datumVonMonat as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:datumVonJahr').value =" & datumVonJahr as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:datumBisTag').value =" & datumBisTag as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:datumBisMonat').value =" & datumBisMonat as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:datumBisJahr').value =" & datumBisJahr as string in document 1
do JavaScript "document.getElementById('capwebSearchForm:searchButton').click();" in document 1
delay 0.5 -- waiting for displaying result
try
set eureka to do JavaScript "document.getElementById('capwebSearchForm:grundbuchAmt').value" in document 1
set eureka to eureka as integer -- exit if it's the results page
on error
exit repeat
end try
set datumVonMonat to (datumVonMonat + 2) mod 12
if datumVonMonat is equal to 1 then set datumVonJahr to datumVonJahr + 1
set datumBisMonat to (datumBisMonat + 2) mod 12
if datumBisMonat is equal to 1 then set datumBisJahr to datumBisJahr + 1
end repeat
end tell