Home > Blockchain >  How do you automate scrolling Instagram DMs?
How do you automate scrolling Instagram DMs?

Time:10-27

I'm trying to scrape my Instagram DMs (direct messages). However, I don't know how to automate scrolling down the column to get the additional usernames that messaged me. I've tried enter image description here

Does anyone have any ideas on how I can modify the script that scrolls down the page to accommodate the column size?

Thank you for taking the time to read my question and help in any way you can.

CodePudding user response:

Instead of targeting the window you should target the messages box element to scroll:

scroll_y = 1000
driver.execute_script(f"document.getElementsByClassName('N9abW')[0].scrollTo(0,{scroll_y})")

if it doesn't work with class name try with Xpath:

path = "//*[@id='react-root']/section/div/div[2]/div/div/div[1]/div[2]/div/div/div"
script = f"document.evaluate({path}, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollTo(0,{scroll_y});"
driver.execute_script(script)

Adjust scroll if needed

CodePudding user response:

You should instead try to use the export data feature on Instagram, you will get the JSON files of all the messages and media you have sent or received. This will make your task a lot easier.

https://help.instagram.com/contact/505535973176353

https://www.instagram.com/download/request/

  • Related