Skip to content

Instantly share code, notes, and snippets.

@elhardoum
Last active June 11, 2019 17:22
Show Gist options
  • Save elhardoum/c0c0fe3c41e7947a22417209f671b78d to your computer and use it in GitHub Desktop.
Save elhardoum/c0c0fe3c41e7947a22417209f671b78d to your computer and use it in GitHub Desktop.
Capture handles from Twitter

This is a workaround for Twitter search API being limited to only tweets from the past week.

Open Twitter on your favourite browser, open dev-tools, then go to console.

Make sure you are on Twitter search page, searching for your mentioned handle or hashtag or whatever.

Enter the code, it will only capture the handles but you can alter it to capture more data of your choosing.

It will attempt to adjust the page scroll to reach the bottom, in order to load more tweets, until you reach the end.

It did help me, hope it helps somebody else.

copy(handles) when you reach the end of the results.

To help you distinguish which Tweets aren't handled yet, you might want to color those processed:

// in your dev-tools console
let style; (style=document.createElement('style')).innerHTML='.eredd{background:red}'; document.head.appendChild(style)

Once all done, the page will still keep scrolling to the bottom of the page, to fix it without a page reload, paste this into the console, run it couple times for 2 seconds.

clearTimeout(setTimeout(console.log, 10) -1)
let handles = [], job
(job = _ => {
document.querySelectorAll('#stream-items-id [data-item-type="tweet"] > [data-screen-name]:not(.eredd)').forEach(div =>
handles.push( div.dataset.screenName ) && div.classList.add('eredd')
)
window.scrollTo(0, document.body.scrollHeight)
setTimeout(job, 2000)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment