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
630 stars 107 forks source link

Login #78

Closed Matteoo98 closed 3 years ago

Matteoo98 commented 3 years ago

Hi, i'm receiving always the error : "InstagramLoginRedirectError", so i want to login. Taking as example your code :

Instantiate the scraper objects

google = Profile('https://www.instagram.com/google/')

Scrape their respective data

google.scrape()

How can i login with username and password ?

tarob0ba commented 3 years ago

Based on what I've seen in the source, I believe (~95%) that you should pass your Instagram session id to the scrape method as indicated by the exception, but you should confirm with @chris-greening, since I don't have an account to test this.

from instascrape import *

session_id = '' # Your session ID - http://valvepress.com/how-to-get-instagram-session-cookie/

google = Profile('https://www.instagram.com/google/')

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={session_id};"}

google.scrape(headers=headers)

print(google.followers)
chris-greening commented 3 years ago

@beckettnormington nailed it exactly, thank you so much!

@Matteoo98, Instagram has been making it increasingly harder to scrape data from their platform so for the most part, you will have to pass a valid session ID as a cookie (as shown above in Beckett's sample code).

Unfortunately, instascrape itself doesn't provide login capabilities as of right now because it runs the risk of getting an account flagged as suspicious but you can manually find your session ID by following these steps.

Hope this helps!

Matteoo98 commented 3 years ago

Yes this would avoid problems, but how long does the session last ? I think that would be more efficent if i will implement a login first then get the sessionid and each time control the validity and in case repeat the login. What is your take on this ?

drctoday commented 2 years ago

@beckettnormington nailed it exactly, thank you so much!

@Matteoo98, Instagram has been making it increasingly harder to scrape data from their platform so for the most part, you will have to pass a valid session ID as a cookie (as shown above in Beckett's sample code).

Unfortunately, instascrape itself doesn't provide login capabilities as of right now because it runs the risk of getting an account flagged as suspicious but you can manually find your session ID by following these steps.

Hope this helps!

Hi Chris,

I am pretty sure I am passing the Session Id (from Google Chrome -- Inspect -- Application -- Instagram -- Session Id, and my Instagram account is logged in). However, I still receive a message indicates that I need to pass an active session id as cookie.

"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"

logbasex commented 2 years ago

I'm facing the same problem.

haresh14 commented 2 years ago

I am facing the same problem