Skip to content

Han-Joon-Hyeok/instagram-comment-scraper

Repository files navigation


Logo

Instagram Comments Crawler

Collect all comments and replies on an instagram post. And pick randomly winners of an event.

View Demo Video

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contact

About The Project

This is developed for collecting all comments of an instagram post and picking randomly winners of an event.

👀 Features

  • Save comments of an instagram post to CSV file.
  • Pick winners and save their account and student ID to CSV file. (Optional)
  • Automatically download chrome driver.

(back to top)

⚙️ Built With

  • Python
  • Selenium

(back to top)

🚀 Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

  • Download Chrome Browser (Not Chrome Driver)
  • Chrome Driver will be downloaded automatically.

Installation

  1. Create a virtual environment

    python -m venv [venv]
  2. Activate virtual environment

    # For Windows
    source [venv]/scripts/activate
    # For Mac or Linux
    source [venv]/bin/activate
  3. Install pip packages

    pip install -r requirements.txt

(back to top)

🔑 Usage

  • ChromeDriver in driver.py is a customized version of Selenium webdriver. So some function of original webdriver is not available.

    from driver import ChromeDriver
    driver = ChromeDriver()
  • Details of customized setting

    • user-agent : randomly changed when launching script.
    • auto download chrome driver : automatically download chrome driver compatible with chrome browser installed.
    • Default download path
      # For windows
      C:/Program Files/chrome or C:/Program Files (x86)/chrome
      # For Mac
      /usr/bin/chrome
  • It is necessary to login to access an instagram post. User account and password are entered on terminal. Password will be hided by getpass when entering input.

    import getpass
    driver.move_to_login_page()
    
    username = input("Input ID : ")
    password = getpass.getpass("Input Password :")
    
    # For only personal usage, you can just put raw data.
    # username = "instagram_account"
    # password = "password"
    
    driver.login_to_instagram(username, password)
  • Set an instagram post url to target_url

    target_url = "https://www.instagram.com/p/..."
    driver.get(target_url)
  • Load all comments and replies.

    driver.load_all_comments()
    driver.load_all_replies()
  • Save all comments and replies to CSV file. It will be saved to comments_{yyyy_mm_dd_hh_mm_ss}.csv

    driver.collect_comments()
  • Close chrome driver at the end of script.

    driver.close()

(back to top)

📮 Contact

Email - [email protected]

(back to top)

About

Cralwers for various purposes using Python Selenium

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages