-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkash.py
85 lines (66 loc) · 2.17 KB
/
kash.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from selenium import webdriver
import time
import random
BASE_URL = "https://www.instagram.com/explore/tags/"
tags = ['ui']
comments = [
'Wow ! Nice Post.',
'Keep it up !!',
'Awesome Work',
'Nice Work'
]
com_len=len(comments)-1
username="username@kash4xd"
password="password@kash4xd"
# options = webdriver.FirefoxOptions()
# options.add_argument('-headless')
browser = webdriver.Firefox(executable_path=r"./geckodriver.exe")
browser.get('https://instagram.com/')
time.sleep(6)
# Entering username
flag = browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input")
flag.send_keys(username)
time.sleep(2)
# Entering password
flag = browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input")
flag.send_keys(password)
time.sleep(2)
# Clicking to log in
flag = browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]")
flag.click()
time.sleep(8)
# Handling notification popup
flag = browser.find_element_by_css_selector('button.aOOlW:nth-child(2)')
flag.click()
for tag in tags:
browser.get(f"{BASE_URL}{tag}/")
time.sleep(5)
temp = browser.find_elements_by_class_name("_bz0w")
# For TOP Post
# posts=temp[:10]
# For RECENT Post
posts=temp[9:]
for i in range(5):
# Opening Post
posts[i].click()
time.sleep(5)
# Liking Post
flag = browser.find_element_by_css_selector('.fr66n > button:nth-child(1)')
flag.click()
time.sleep(5)
# Typing Comment
flag = browser.find_element_by_css_selector('._15y0l > button:nth-child(1)')
flag.click()
time.sleep(2)
flag = browser.find_element_by_css_selector('.Ypffh')
flag.send_keys(comments[random.randint(0,com_len)])
time.sleep(2)
# Posting Comment
flag = browser.find_element_by_css_selector('.X7cDz > button:nth-child(2)')
flag.click()
time.sleep(3)
# Closing Post
flag = browser.find_element_by_css_selector('.BI4qX > button:nth-child(1)')
flag.click()
time.sleep(4)
browser.quit()