Seeking to extract data from this specific website, I've developed a javascript function that effectively retrieves the necessary information:
const total_planning_applications = 39437
const min_value = 39407
var superArray = []
var i = 1
window.location.href = "http://www2.ashfield.gov.uk/cfusion/Planning/plan_arc_results2_v_date.cfm?fromyear=1974&frommonth=01&fromday=01&to_year=2017&to_month=06&to_day=26&StartRow=" + (total_planning_applications - i*10)
window.onload = loop
//primary loop handler triggered by the window.onload event. See: https://stackoverflow.com/questions/588040/window-onload-vs-document-onload for more details.
function loop(){
concatTables(superArray,document.getElementsByTagName("tbody")[0],function(){
i++
if(min_value < (total_planning_applications - i*10)){
window.location.href = "http://www2.ashfield.gov.uk/cfusion/Planning/plan_arc_results2_v_date.cfm?fromyear=1974&frommonth=01&fromday=01&to_year=2017&to_month=06&to_day=26&StartRow=" + (total_planning_applications - i*10)
window.onload = loop
}
})
}
//merges a table from the Ashfield council's website with the mainArray (excluding headers)
function concatTables(mainArray,table,callback){
if(mainArray=[]){
mainArray.push(["RefNum","RefLink","Application","Location","Proposal","ADCDecision","ValidDate","Map","MapLink"])
}
arr = getArray(table)
arr.shift()
mainArray.push(arr)
}
//retrieves an array from the table on the Ashfield council's website
function getArray(table){
var ret = []
for(var i=0;i<table.children.length;i++){
var row = table.children[i]
var aRow = []
var bSkip = false
for(var j=0;j<row.children.length;j++){
if (row.children.length==1){
bSkip = true
break;
}
aRow.push(row.children[j].innerText.trim().replace(/\r|\n/g," "))
if(row.children[j].getElementsByTagName("a")[0]!=undefined){
aRow.push(row.children[j].getElementsByTagName("a")[0].href)
}
}
if(!bSkip){
ret.push(aRow)
} else {
bSkip = false
}
}
return ret
}
However, upon trying to execute the javascript code via the console, it halts after the initial loop. This interruption is due to security measures implemented by browsers to prevent cross-website scripting.
In this scenario, the objective isn't to navigate to another site but rather to a particular query string. Is there a method to achieve this without disrupting the javascript runtime?
If not, are there alternative solutions aside from utilizing something like Electron?