Chrome DevTools tip #1
Jan 22, 2021
How to loop through JS elements by classname… useful for quickly scraping Google Scholar if you need somebody’s total number of citations:
var mytotal=0;// ClassName will likely be a string different to that shown:
let myquery = document.getElementsByClassName(“gsc_a_ac”)for (var i=0, item; item = myquery[i]; i++) {
var mycount=parseInt(item.innerHTML);
console.log(mycount); // <== we can easily monitor the increment
mytotal=mytotal+mycount;
console.log(mytotal); // <== we can easily copy/paste the answer
}
See it in use: