-
Notifications
You must be signed in to change notification settings - Fork 0
/
insta_dm.py
50 lines (46 loc) · 2.19 KB
/
insta_dm.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time,random
between_messages = 2000
browser = webdriver.Chrome('chromedriver')
def auth(username,password):
try:
browser.get('https://www.instagram.com/accounts/login/?next=/direct/inbox/')
time.sleep(10)
input_username = browser.find_element_by_name('username')
input_password = browser.find_element_by_name('password')
input_username.send_keys(username)
time.sleep(3)
input_password.send_keys(password)
time.sleep(2)
input_password.send_keys(Keys.ENTER)
except Exception as err:
print(err)
browser.quit()
def send_message(users,messages):
try:
time.sleep(5)
browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div/div/button').click()
time.sleep(5)
browser.find_element_by_xpath('/html/body/div[5]/div/div/div/div[3]/button[2]').click()
time.sleep(5)
for user in users:
browser.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button').click()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input').send_keys(user)
time.sleep(3)
browser.find_element_by_xpath('/html/body/div[6]/div/div/div[2]/div[2]').find_element_by_tag_name('button').click()
browser.find_element_by_xpath('/html/body/div[6]/div/div/div[1]/div/div[3]/div/button/div').click()
time.sleep(5)
browser.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[2]/textarea').send_keys(messages)
time.sleep(3)
browser.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[3]/button').click()
time.sleep(2)
except Exception as err:
print(err)
browser.quit()
password = 'cosdp@29' # write your login password here
username = 'cosdp_test' # write your login username here
users = ['subin_sk','_himanisoni_','mitalilohar_']
auth(username,password)
send_message(users,'hello hello')