-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
66 lines (63 loc) · 2.43 KB
/
run.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
62
63
64
65
66
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from instagram_private_api import Client, ClientCompatPatch
import time
import os
print("---------------------")
#uname = "themayborn_"
#pwd = "roomno108"
uname="<username>"
pwd="<password>"
count = 0
print("\nInitializing Process...")
options = Options()
options.add_argument("--window-size=1366x720")
options.add_argument("--incognito")
chromedriver_path = 'C:/Users/sande/Downloads/chromedriver_win32/chromedriver.exe'
print("\nProcess started.")
f = open("follow_req.txt","w")
browser = webdriver.Chrome(executable_path=chromedriver_path, options=options) #Star Browser
browser.get("https://www.instagram.com/")
time.sleep(3) #Waiting 3 seconds after we open the page.
#IG Login
#login = browser.find_element_by_xpath ("//*[@id='react-root']/section/main/article/div[2]/div[2]/p/a")
#login.click()
#time.sleep (2)
username=browser.find_element_by_name ("username")
username.send_keys(uname)
password =browser.find_element_by_name ("password")
password.send_keys(pwd)
login_button = browser.find_element_by_xpath ("//button[@type='submit']")
login_button.click()
time.sleep(6)
browser.get("https://www.instagram.com/accounts/access_tool/current_follow_requests")
while True:
try:
vm_button = browser.find_element_by_xpath ('//*[@id="react-root"]/section/main/div/article/main/button')
vm_button.click()
time.sleep(2)
count+=1
if count == 10:
print("\n****Can't go further too many scripts, you to run script again after it completed.")
break
except NoSuchElementException:
break
cfreq_source = browser.find_elements_by_xpath("//div[@class='-utLf']")
for x in cfreq_source:
f.write(x.text+"\n")
f.close()
print("\nGot the users you have sent follow request in \"follow_req.txt\" file, now exiting browser..." )
browser.quit()
print("\nThe following are available users to unfollow:\n")
f=open("follow_req.txt","r")
print(f.read())
# Start deleting the follow requests
api = Client(uname, pwd)
f = open("follow_req.txt", "r").read().split("\n")
for x in f:
if bool(x):
user_info = api.username_info(x)
uid = user_info['user']['pk']
api.friendships_destroy(uid)
print("\nFollow request cancelled for: "+x)