Created
August 23, 2019 13:51
-
-
Save erd0s/6c005079386d586bcbc6230f9a5a9b42 to your computer and use it in GitHub Desktop.
scrape-twitter-retweet-handles.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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