DISCLAIMER: I do not know JS, it is an assignment for my work.
I have been asked to withdraw scrape some data from a Google Marketing page using Chrome Console.
The HTML code I need to scrape looks like this:
I made the following code where I created a dictionary and then used document.Selector()to take the data but I only take it from one row.
var IntegrationDetails = [{}]
IntegrationDetails[0]["Property Name"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Advertiser"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Tracking ID"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Account"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Organisation name"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Integrations with reporting data"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Integrations with Cost Data"] = document.querySelector("JSPath").innerText
IntegrationDetails[0]["Integrations with Remarketing Lists"] = document.querySelector("JSPath").innerText
copy(IntegrationDetails)
I do not know how to iterate over every row in the mat-tab element and append each row to the dictionary.
CodePudding user response:
The solution that I found it worked is the one below. I also needed to increment the [i] based on the length of the table in order to not overwrite the data.
var IntegrationDetails = []
for(let i=0;i < document.querySelectorAll('mat-row').length; i ) {
IntegrationDetails.push( {
"Property Name": document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[1].innerText,
"Advertiser": document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[2].innerText,
"Tracking ID" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[3].innerText,
"Account" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[4].innerText,
"Organisation name" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[5].innerText,
"Int with report data" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[6].innerText,
"Int with Cost Data" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[7].innerText,
"Int with Remarketing Lists" : document.querySelectorAll('mat-row')[i].querySelectorAll("mat-cell")[8].innerText
})
}
copy(IntegrationDetails)
