Skip to content

Instantly share code, notes, and snippets.

@tuur29
Last active October 23, 2019 17:10
Show Gist options
  • Save tuur29/40519adc8dc1baa99b8cacd868c6f3bc to your computer and use it in GitHub Desktop.
Save tuur29/40519adc8dc1baa99b8cacd868c6f3bc to your computer and use it in GitHub Desktop.
Scrape slack search results

Scrape slack search results

Usage:

  • Search for from:NAME in Slack
  • Select some filters etc... (perhaps make sure sorting is on most recent?)
  • Paste this script into the dev tools and run in
  • Wait for the output to finish
  • Once you hit the 100th page you need to filter by ending date and re-run the script
  • Now concatenate these outputs together manually and run the following shell script to get you word count: https://gist.github.com/decrn/8f6454f514f481b5f5bd9df33e4e221e
(function () {
const all = [];
const waitForNext = (callback) => {
const interval = setInterval(() => {
if (!document.querySelector('.c-infinite_spinner')) {
clearInterval(interval);
callback();
}
}, 50);
};
const scrapeMessages = () => {
document.querySelectorAll('.c-search__expand').forEach(b => b.click());
document.querySelectorAll('.c-mrkdwn__pre, .c-mrkdwn__code').forEach(d => { d.innerHTML = ' '; });
all.push(...Array.from(document.querySelectorAll('.c-search_message__body')).map(d => d.textContent));
setTimeout(() => {
const button = document.querySelector('.c-search__pager__button_forward');
const list = document.querySelector('.c-search_focus_managed_list');
if (button && list.children.length > 0) {
button.click();
waitForNext(scrapeMessages);
} else {
if (list.children.length === 0) {
document.querySelector('.c-search__pager__button__back').click();
}
console.log(all.join("\n"));
}
}, 10);
};
scrapeMessages();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment