This is developed for collecting all comments of an instagram post and picking randomly winners of an event.
- 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.
- Python
- Selenium
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.
- Download Chrome Browser (Not Chrome Driver)
- Chrome Driver will be downloaded automatically.
-
Create a virtual environment
python -m venv [venv]
-
Activate virtual environment
# For Windows source [venv]/scripts/activate # For Mac or Linux source [venv]/bin/activate
-
Install pip packages
pip install -r requirements.txt
-
ChromeDriver
indriver.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()
Email - [email protected]