1
+ from selenium import webdriver
2
+ from webdriver_manager .chrome import ChromeDriverManager
3
+ from selenium .webdriver .common .keys import Keys
4
+ from getpass import getpass
5
+ import time
6
+
7
+ chrome = webdriver .Chrome (ChromeDriverManager ().install ())
8
+ chrome .get ("https://www.instagram.com" )
9
+ time .sleep (10 )
10
+
11
+ username = chrome .find_element_by_xpath ('//*[@id="loginForm"]/div/div[1]/div/label/input' )
12
+ username .send_keys (input ("Enter your username: " )) #enter username
13
+ print ("Enter your Password: " )
14
+ password = chrome .find_element_by_xpath ('//*[@id="loginForm"]/div/div[2]/div/label/input' )
15
+ pswd = getpass ()
16
+ password .send_keys (pswd )
17
+ login_button = chrome .find_element_by_xpath ('//*[@id="loginForm"]/div/div[3]' )
18
+ login_button .click ()
19
+ time .sleep (10 )
20
+
21
+ search_bar = chrome .find_element_by_xpath ('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/input' )
22
+ search_bar .send_keys (input ("Enter the username of the other person: " )) #enter the username to be searched
23
+ time .sleep (7 )
24
+ search_bar .send_keys (Keys .ENTER )
25
+ search_bar .send_keys (Keys .ENTER )
26
+
27
+ time .sleep (2 )
28
+
29
+ post = chrome .find_element_by_xpath ('//*[@id="react-root"]/section/main/div/div[3]/article/div[1]/div/div[1]/div[1]/a/div[1]/div[2]' )
30
+ post .click ()
31
+ time .sleep (2 )
32
+ like_button = chrome .find_element_by_xpath ('/html/body/div[5]/div[2]/div/article/div[3]/section[1]/span[1]/button' )
33
+ like_button .click ()
34
+ next_button = chrome .find_element_by_xpath ('/html/body/div[5]/div[1]/div/div/a' )
35
+ next_button .click ()
36
+ time .sleep (2 )
37
+
38
+ while True :
39
+ try :
40
+ like_button = chrome .find_element_by_xpath ('/html/body/div[5]/div[2]/div/article/div[3]/section[1]/span[1]/button' )
41
+ like_button .click ()
42
+ next_button = chrome .find_element_by_xpath ('/html/body/div[5]/div[1]/div/div/a[2]' )
43
+ next_button .click ()
44
+ time .sleep (5 )
45
+ except :
46
+ close_button = chrome .find_element_by_xpath ('/html/body/div[5]/div[3]/button' )
47
+ close_button .click ()
48
+ break
0 commit comments