instascrape icon indicating copy to clipboard operation
instascrape copied to clipboard

instascrape.exceptions.exceptions.InstagramLoginRedirectError: Instagram is redirecting you to the login page instead of the page you are trying to scrape. This could be occuring because you made too many requests too quickly or are not logged into Instagram on your machine. Try passing a valid session ID to the scrape method as a cookie to bypass the login requirement

Open monajalal opened this issue 2 years ago • 2 comments

Thanks a lot for the great API. Do you know how I can fix this error?

(insta) [jalal@goku insta-scrape]$ python test.py
/scratch3/venv/insta/lib/python3.8/site-packages/instascrape/core/_static_scraper.py:134: MissingCookiesWarning: Request header does not contain cookies! It's recommended you pass at least a valid sessionid otherwise Instagram will likely redirect you to their login page.
  warnings.warn(
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    google_post.scrape()
  File "/scratch3/venv/insta/lib/python3.8/site-packages/instascrape/scrapers/post.py", line 73, in scrape
    return_instance = super().scrape(
  File "/scratch3/venv/insta/lib/python3.8/site-packages/instascrape/core/_static_scraper.py", line 144, in scrape
    return_data = self._get_json_from_source(self.source, headers=headers, session=session)
  File "/scratch3/venv/insta/lib/python3.8/site-packages/instascrape/core/_static_scraper.py", line 265, in _get_json_from_source
    self._validate_scrape(json_dict)
  File "/scratch3/venv/insta/lib/python3.8/site-packages/instascrape/core/_static_scraper.py", line 301, in _validate_scrape
    raise InstagramLoginRedirectError
instascrape.exceptions.exceptions.InstagramLoginRedirectError: Instagram is redirecting you to the login page instead of the page you are trying to scrape. This could be occuring because you made too many requests too quickly or are not logged into Instagram on your machine. Try passing a valid session ID to the scrape method as a cookie to bypass the login requirement
(insta) [jalal@goku insta-scrape]$ cat test.py 
from instascrape import * 

google = Profile('https://www.instagram.com/tresorbutik/')
google_post = Post('https://www.instagram.com/p/CSCNBuljxLv/')
google_hashtag = Hashtag('https://www.instagram.com/explore/tags/fashion/')

# Scrape their respective data 
google.scrape()
google_post.scrape()
google_hashtag.scrape()

print(google.followers)
print(google_post['hashtags'])
print(google_hashtag.amount_of_posts)

monajalal avatar Aug 02 '21 21:08 monajalal

You should get your login sessionid cookie from instagram (Using a cookie editor of some sort) and then add it to the headers when you scrape your data:

headers = {
  'cookie': 'sessionid=YOUR_SESSIONID_HERE'
}
google = Profile('https://www.instagram.com/tresorbutik/')
google.scrape(headers=headers)

code1dot avatar Nov 05 '21 13:11 code1dot

You should get your login sessionid cookie from instagram (Using a cookie editor of some sort) and then add it to the headers when you scrape your data:

headers = {
  'cookie': 'sessionid=YOUR_SESSIONID_HERE'
}
google = Profile('https://www.instagram.com/tresorbutik/')
google.scrape(headers=headers)

This is still not working for me. but still trying

kareemrasheed89 avatar May 13 '22 03:05 kareemrasheed89