DEV Community

Cover image for Scrape data from Instagram with instascrape and Python

Scrape data from Instagram with instascrape and Python

Chris Greening on October 20, 2020

❓ What the heck is instascrape? instascrape is a lightweight library designed for scraping data from Instagram using Python! It makes no...
Collapse
 
athiyarastogi profile image
Athiya Rastogi

When I enter the Profile name, the code throws this warning:

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.
MissingCookiesWarning

Could you please help with this?

Collapse
 
chrisgreening profile image
Chris Greening

Hello! Instagram has started requiring a valid sessionid cookie when making HTTP requests. Check out this blog post for more information on getting your sessionid for scraping

Technically it is just a warning and you can usually get away with a couple scrapes before they have a problem but I've found after about a dozen scrapes they start redirecting to their login page

Collapse
 
athiyarastogi profile image
Athiya Rastogi

Thank you!

Collapse
 
vagnerbelfort profile image
Vagner Belfort • Edited

Hi Chis, how are you?

I am trying to run your tutorials but I have an error could you help me?

i.ibb.co/52DX7hN/Screenshot-from-2...

Collapse
 
chrisgreening profile image
Chris Greening

Hey Vagner! That's an error I'm working on literally as we speak. I think Instagram tightened their restrictions overnight or something, I woke up to this error as well. I think what's happening is every GET request is being returned a 429 HTTP status code. I'm adding more robust headers to the requests.get calls that instascrape makes and it seems to have fixed the problem so check the officical repository later today for the 1.4.0 release and then reinstall from PyPI. Thanks for the patience!

Collapse
 
chrisgreening profile image
Chris Greening

Okay, 1.4.0 is live, go try that out and let me know if that works for you!

Collapse
 
booshnam profile image
Booshnam

Hi, I am getting the following error. Could someone help me out with this?

Traceback (most recent call last):

File "C:\Users\booshnam.d.spyder-py3\instascrape.py", line 3, in
chris = Profile('chris_greening')

TypeError: init() missing 1 required positional argument: 'data'

Collapse
 
joemol94 profile image
Joemol94

Getting same error.
The issue is still open - github.com/chris-greening/instascr...

Collapse
 
govindsingh9447 profile image
GovindSingh9447

Hello Chris,
I used this awesome library but my code show some error, please help me out!!

from instascrape import Profile
profile = Profile('chris_greening')
profile.scrape()

C:\Python\Python39\python.exe "C:/Users/hp/PycharmProjects/instagram/insta reels.py"
Traceback (most recent call last):
File "C:\Users\hp\PycharmProjects\instagram\insta reels.py", line 1, in
from instascrape import Profile
File "C:\Python\Python39\lib\site-packages\instascrape_init_.py", line 4, in
from helpers import extract_email
ModuleNotFoundError: No module named 'helpers'

Process finished with exit code 1

Collapse
 
younes profile image
Younes

Hello Chris,
I used this awesome library to scrap comments from posts with specific hashtags, but the issue i have is, i can't get all the comments of the post, also, it only gives me 12 posts!
how can i make retrieve all comments and also all posts?
Thanks

Collapse
 
rajanverma_me profile image
Aarvy • Edited

I am not even able to run those 3 lines. Getting this error

ImportError: cannot import name 'Profile' from 'instascrape' (/home/rajanverma/workspace/indie_hacks/offline/instascrape.py)

Collapse
 
chrisgreening profile image
Chris Greening

Hello Aarvy, I saw your issue on GitHub, hope you found a solution!

Collapse
 
rajanverma_me profile image
Aarvy

yes. shall I remove the comment?

Collapse
 
geo3huruf profile image
geo3huruf

error helpers

Collapse
 
jnascimentocode profile image
Jean Nascimento

I am not even able to run those 3 lines. See?

Image description

Collapse
 
fatima2309 profile image
Fatima-2309

Unable to run even these 3 lines :(

Getting this error:
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

Pleaase help !