Skip to content

Instantly share code, notes, and snippets.

@johnfewell
Forked from sivcan/script.js
Last active April 18, 2023 17:28
Show Gist options
  • Save johnfewell/8bdc8a782315cdf672cd2a3311e05de1 to your computer and use it in GitHub Desktop.
Save johnfewell/8bdc8a782315cdf672cd2a3311e05de1 to your computer and use it in GitHub Desktop.
Scrape Airtable to CSV [Script]
/**
1. Observed the Network tab in chrome devtools
2. Found out the request that has all the data
3. Right click the data (response of the network request) -> Store as global variable (this basically makes the entire data
available in the Console of DevTools) - it’s stored under a variable called as temp1use that to convert my data.
4. Observed the payload, figured out how columnIds are mapped to the data that is present in the entire response JSON.
5. Wrote the following scripts to access the data:
**/
let columns = temp1.table.columns;
function getData(row) {
return columns.reduce((acc, column) => {
if (row.cellValuesByColumnId[column.id]) {
acc[[column.name]] = row.cellValuesByColumnId[column.id];
}
return acc;
}, {});
}
let data = temp1.table.rows.map((row) => {
return getData(row);
});
function convertToCSV(data) {
const header = Object.keys(data[0]).join(',') + '\n';
const rows = data
.map((row) => {
return Object.values(row)
.map((value) => `"${value}"`)
.join(',');
})
.join('\n');
return header + rows;
}
const csvData = convertToCSV(data);
copy(csvData); // Copies the entire CSV data to CLIPBOARD!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment