Skip to content

Instantly share code, notes, and snippets.

@erd0s
Created August 23, 2019 13:51
Show Gist options
  • Save erd0s/6c005079386d586bcbc6230f9a5a9b42 to your computer and use it in GitHub Desktop.
Save erd0s/6c005079386d586bcbc6230f9a5a9b42 to your computer and use it in GitHub Desktop.
scrape-twitter-retweet-handles.js
// Find the element
let scrollableElement = document.querySelector("div[aria-label='Timeline: Retweeted by']").parentElement.parentElement.parentElement;
// Get the height
let elementHeight = scrollableElement.scrollHeight;
// Scroll through and grab all divs each time
async function grabthem() {
let scrolls = Array.from(Array(Math.floor(elementHeight/500)).keys()).map(o => o * 500);
let retweeters = [];
for (let scrollVal of scrolls) {
scrollableElement.scrollTop = scrollVal;
await getWait(200);
let people = Array.from(scrollableElement.querySelectorAll("div > span")).filter(o => /^@/.test(o.innerText)).map(o => o.innerText);
retweeters.push(...people);
}
// Filter at the end
alert([...new Set(retweeters)].join(", "));
}
function getWait(length) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, length);
});
}
grabthem();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment