Skip to content

Instantly share code, notes, and snippets.

Last active March 6, 2021 05:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save missionmike/667bf157d7a0c11a17f097383a21b535 to your computer and use it in GitHub Desktop.
Get CID from Google My Business Table
* Instructions:
* 1. Visit your Google My Business admin section to view the "Businesses" table.
* If there is a "See your profile" button on the far right, this script might
* help you scrape for the Google Maps CIDs.
* 2. Open console, copy/paste this script there and execute. Data should get
* copied to the clipboard at the end of script.
* 3. Open Excel or Google Sheets, etc., and paste resulting data. Last two columns
* should include CID and Maps Link.
let rows = [];
document.querySelectorAll("tr").forEach(($tr) => {
// Don't proceed if <tr> doesn't contain a relevant <a>
if (!$tr.querySelector(`a[href*="place?id="]`)) return;
let tr = [];
$tr.querySelectorAll("td").forEach(($td) => {
if ($td.textContent) tr.push($td.textContent);
// Populate cells for CID based on link value
let $a = $tr.querySelector(`a[href*="place?id"]`),
url = $a.getAttribute("href"),
cid = url.split("?id=")[1].split("&")[0];
tr.push(url, cid, `${cid}`);
// Copy tab-delineated values to clipboard
let $textarea = document.createElement("textarea");
$textarea.setAttribute("readonly", "");
$ = { position: "absolute", left: "-9999px" };
$textarea.value = rows
.map(function (d) {
return d.join("\t");
// Debug output
console.log("\n%cCopied tab-delineated text data to clipboard.", "color:green; font-size:20px;");
`%cTotal columns: %c${rows[rows.length - 1].length}`,
"color:green; font-size:20px;"
console.log(`%cTotal rows: %c${rows.length}`, "font-size:20px", "color:green; font-size:20px;");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment