Skip to content

Instantly share code, notes, and snippets.

@sysnucleus
Created June 29, 2022 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sysnucleus/15991d5f19388909f26e10efc0b43f94 to your computer and use it in GitHub Desktop.
Save sysnucleus/15991d5f19388909f26e10efc0b43f94 to your computer and use it in GitHub Desktop.
WebHarvy Codes for Google Reviews Scraping
// Pagination JavaScript Code
-------------------------------
lists = document.getElementsByClassName('gws-localreviews__general-reviews-block');
list = lists[lists.length-1];
list.children[list.childElementCount-1].scrollIntoView();
// Code to expand all reviews
---------------------------------
els = document.getElementsByClassName('review-more-link');
for (i = 0; i < els.length; i++) {
els[i].click();
}
// Code to collate all reviews
---------------------------------
var groups = document.getElementsByClassName('gws-localreviews__general-reviews-block');
var parent = groups[0];
for (var i = groups.length - 1; i >= 1; i--) {
var group = groups[i];
for (var j = group.children.length - 1; j >= 0; j--) {
parent.appendChild(group.children[j]);
}
}
// RegEx to get rating
-------------------------
aria-label="Rated ([^\s]*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment