This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
forked from InstaPy/instagram-profilecrawl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrawl_profile.py
executable file
·61 lines (49 loc) · 2.08 KB
/
crawl_profile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3.5
"""Goes through all usernames and collects their information"""
import sys
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from util.account import login
from util.chromedriver import init_chromedriver
from util.cli_helper import get_all_user_names
from util.datasaver import Datasaver
from util.extractor import extract_information
from util.settings import Settings
chrome_options = Options()
chromeOptions = webdriver.ChromeOptions()
prefs = {'profile.managed_default_content_settings.images': 2, 'disk-cache-size': 4096}
chromeOptions.add_experimental_option("prefs", prefs)
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--lang=en-US')
chrome_options.add_argument('--headless')
chrome_options.add_experimental_option('prefs', {'intl.accept_languages': 'en-US'})
capabilities = DesiredCapabilities.CHROME
try:
browser = init_chromedriver(chrome_options, capabilities)
except Exception as exc:
print(exc)
sys.exit()
try:
usernames = get_all_user_names()
for username in usernames:
print('Extracting information from ' + username)
information = []
user_commented_list = []
try:
if len(Settings.login_username) != 0:
login(browser, Settings.login_username, Settings.login_password)
information, user_commented_list = extract_information(browser, username, Settings.limit_amount)
except:
print("Error with user " + username)
sys.exit(1)
Datasaver.save_profile_json(username, information)
print("Number of users who commented on their profile is ", len(user_commented_list), "\n")
Datasaver.save_profile_commenters_txt(username, user_commented_list)
print("\nFinished. The json file and nicknames of users who commented were saved in profiles directory.\n")
except KeyboardInterrupt:
print('Aborted...')
finally:
browser.delete_all_cookies()
browser.close()