chris-greening / instascrape

Powerful and flexible Instagram scraping library for Python, providing easy-to-use and expressive tools for accessing data programmatically
https://chris-greening.github.io/instascrape/
MIT License
636 stars 111 forks source link

Even after passing a valid cookie, the Instagram account gets disabled (update: permanently) #141

Open marco97pa opened 3 years ago

marco97pa commented 3 years ago

Some weeks ago I started noticing a bad behavior: even after passing a valid session_id cookie, the Instagram account used to scrape gets disabled after some requests. I need to log in to the Instagram website and manually verify my account using a phone number in order to avoid that my account gets a permanent ban and get a new session_id cookie.

I think that Instagram enforced this behavior against bots: it happened before that I needed to regenerate a valid session_id, but once every 1 or 2 months and it was ok. Now the account gets soft-banned after only a few days of making requests using this API

The code that causes this issue:

# Get Instagram cookies
instagram_sessionid = os.environ.get('INSTAGRAM_SESSION_ID')
headers = {"user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.57",
"cookie": f"sessionid={instagram_sessionid};"}

...

# Get profile of an artist
profile = Profile(artist)
profile = profile.scrape(headers=headers, inplace=False)
...
# Get recent posts of that profile
recents = profile.get_recent_posts()

    for recent in recents:
      recent.scrape(headers=headers)
      ...

I run this code every 30 minutes, every day

marco97pa commented 3 years ago

Update: in the following weeks I needed to manually verify my account sending a video as a proof to Instagram

After 2 months my account has been permanently disabled, even if I passed all the video verification above (I am a human, not a bot).

Screenshot_2021-11-10-16-59-12-327_com instagram android

I used my account only to scrape some data using the code above and I posted some photos once a while.

THIS COMMENT IS TO ALERT ALL THE USERS OF THIS LIBRARY: YOU COULD GET BANNED ANYTIME. Use a secondary Instagram account to avoid loss of data.

clouedoc commented 2 years ago

I wonder if maintaining an account farm could fix this.