View difference between Paste ID: NncgMuFZ and ri620G4h
SHOW: | | - or go back to the newest paste.
1
# coding: utf-8
2
from selenium import webdriver
3
from selenium.webdriver.common.keys import Keys
4
import time
5
def get_comment_input(browser):
6
    comment_input = browser.find_elements_by_xpath(
7
        '//textarea[@placeholder = "Add a comment…"]')
8
    if len(comment_input) <= 0:
9
        comment_input = browser.find_elements_by_xpath(
10
            '//input[@placeholder = "Add a comment…"]')
11
    return comment_input 
12
13
def open_comment_section(browser):
14
    missing_comment_elem_warning = (
15
        '--> Warning: Comment Button Not Found:'
16
        ' May cause issues with browser windows of smaller widths')
17
    comment_elem = browser.find_elements_by_xpath(
18
        "//a[@role='button']/span[text()='Comment']/..")
19
    if len(comment_elem) > 0:
20
        try:
21
            browser.execute_script(
22
                "arguments[0].click();", comment_elem[0])
23
        except WebDriverException:
24
            print(missing_comment_elem_warning)
25
    else:
26
        print(missing_comment_elem_warning)
27
28
29
browser = webdriver.Chrome("/home/gozmit/Downloads/chromedriver") 
30
browser.get('https://www.instagram.com/accounts/login/')
31
time.sleep(2)
32
username = browser.find_element_by_xpath('//input[@name="username"]')
33-
username.send_keys('krazeyk.1234')
33+
username.send_keys('username')
34
password = browser.find_element_by_xpath('//input[@name="password"]')
35-
password.send_keys('Ayushagg@123')
35+
password.send_keys('password')
36
logIn = browser.find_element_by_css_selector('._qv64e')
37
logIn.click()
38
time.sleep(5)
39
count=0
40
L = ['asmm','eppic','wonderland','woooow','cooool','wonderful','kepitup','good','perfect click','beaches']
41
while count < 10:
42
	browser.get("https://www.instagram.com/p/BeFXzKjDPwM/?taken-by=dm_ur_creativity");
43
	browser.execute_script("window.scrollTo(0, 800)") 
44
	open_comment_section(browser)
45
	comment_input = get_comment_input(browser)
46
	if len(comment_input) > 0:
47
		comment_input[0].clear()
48
		comment_input = get_comment_input(browser)
49
		browser.execute_script("arguments[0].value = '" + L[count] + " ';", comment_input[0])
50
		comment_input[0].send_keys("\b")
51
		comment_input = get_comment_input(browser)
52
		comment_input[0].submit()
53
		count = count+1
54
		time.sleep(20)
55
#comm.clear()
56
#comm.send_keys("and some", Keys.ENTER);
57
#comment.send_keys(Keys.ENTER)
58
#browser.quit()