-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstagram_script.py
More file actions
122 lines (77 loc) · 4.11 KB
/
instagram_script.py
File metadata and controls
122 lines (77 loc) · 4.11 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.firefox.options import Options
# Read the JSON file
with open('data.json', 'r') as json_file:
data = json.load(json_file)
# Access the name and age from the JSON file
name = data.get("name")
password = data.get("password")
url="https://www.instagram.com/"
# To run Selenium without browser window
# options = Options()
# options.add_argument("--headless")
# browser = webdriver.Firefox(options=options)
browser = webdriver.Firefox()
browser.get(url)
browser.implicitly_wait(10)
ur_username =name
ur_password =password
print(type(ur_password))
username=browser.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div/div/div[1]/div[1]/div/section/main/article/div[2]/div[1]/div[2]/div/form/div/div[1]/div/label/input")
# <input aria-label="Phone number, username, or email" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="75" class="_aa4b _add6 _ac4d _ap35" dir="" type="text" value="" name="username">
# username=browser.find_element(By.CLASS_NAME,"_aa4b _add6 _ac4d _ap35")
# <class="_aa4b _add6 _ac4d _ap35">
username.send_keys (ur_username)
# password =browser.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div/div/div[1]/div[1]/div/section/main/article/div[2]/div[1]/div[2]/div/form/div/div[2]/div/label/input")
password =browser.find_element(By.CSS_SELECTOR,"div._ab32:nth-child(2) > div:nth-child(1) > label:nth-child(1) > input:nth-child(2)")
password.send_keys(ur_password)
# div._ab32:nth-child(2) > div:nth-child(1) > label:nth-child(1) > input:nth-child(2)
# <input aria-label="Password" aria-required="true" autocapitalize="none" autocorrect="off" class="_aa4b _add6 _ac4d _ap35" type="password" value="" name="password">
# /html/body/div[2]/div/div/div[2]/div/div/div[1]/div[1]/div/section/main/article/div[2]/div[1]/div[2]/div/form/div/div[2]/div/label/input
login_button = browser.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/div/div/div[1]/div[1]/div/section/main/article/div[2]/div[1]/div[2]/div/form/div/div[3]/button/div")
login_button.click()
time.sleep(5)
save_info = browser.find_element(By.CSS_SELECTOR,"div.x1i10hfl")
save_info.click()
time.sleep(5)
noti = browser.find_element(By.CSS_SELECTOR,"button._a9--:nth-child(2)")
noti.click()
time.sleep(5)
# profile
click_pf = browser.find_element(By.XPATH,"/html/body/div[1]/div/div/div[2]/div/div/div[1]/div[1]/div[2]/div/div/div/div/div[2]/div[8]/div/span/div/a")
click_pf.click()
time.sleep(5)
browser.save_screenshot("profile.png")
# Following count
following_count = browser.find_element(By.CSS_SELECTOR,"li.xl565be:nth-child(3) > div:nth-child(1) > a:nth-child(1) > span:nth-child(1) > span:nth-child(1)")
print("following count",following_count.text)
# Follower count
follower_count = browser.find_element(By.CSS_SELECTOR,"li.xl565be:nth-child(2) > div:nth-child(1) > a:nth-child(1) > span:nth-child(1) > span:nth-child(1)")
print("follower count",follower_count.text)
# li.xl565be:nth-child(2) > div:nth-child(1) > a:nth-child(1) > span:nth-child(1) > span:nth-child(1)
# Post Count
post_count = browser.find_element(By.CSS_SELECTOR,"li.xl565be:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)")
print("Post count",post_count.text)
# li.xl565be:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)
# **************************************************
# Paths for elements
# following
# li.xl565be:nth-child(3) > div:nth-child(1) > a:nth-child(1)
# followers
# li.xl565be:nth-child(2) > div:nth-child(1) > a:nth-child(1)
# options = webdriver.FirefoxOptions()
# original_size = browser.get_window_size()
# #Find height of the page
# height = browser.execute_script("return document.body.parentNode.scrollHeight")
# time.sleep(5)
# # browser.quit()
# browser = webdriver.Firefox(options=options)
# browser.set_window_size(original_size['width'], height)
# browser.save_screenshot('Fullpf.png')
# .....
# Date joined
# .wbloks_98 > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > span:nth-child(2)
# browser.close()