-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinsta_like.py
82 lines (64 loc) · 2.24 KB
/
insta_like.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
# -*- coding: UTF-8 -*-
''' writing a script to like posts in my thread '''
import logging
import pickle
from selenium.webdriver.common.by import By
import insta_base as ib
import insta_delete as id
log = logging.getLogger(__name__)
def find_likes(browser):
try:
log.info('finding like svg element')
btn = browser.find_elements(by=By.XPATH, value="//*[local-name()='svg' and @aria-label='Like']")
log.info(f'found {len(btn)} btns')
return btn
except Exception as ex:
log.info('like element not found', exc_info=True)
return None
def find_like(browser):
try:
log.info('finding like svg element')
btn = browser.find_elements(by=By.XPATH, value="//*[local-name()='svg' and @aria-label='Like']")[0]
log.info(f'found like button')
return btn
except Exception as ex:
log.info('like element not found', exc_info=True)
return None
def delete_with_cookies():
driver = ib.get_driver()
driver.get("https://www.instagram.com/")
ib.load_cookies(driver)
ib.random_time()
id.delete_posts(browser=driver)
def inspect_cookies():
cookies = pickle.load(open("data/cookies.pkl", "rb"))
log.info('loading cookies')
for cookie in cookies:
log.info(cookie)
def like_post(driver):
ib.bypass_notification_prompt(driver)
like_btn = find_like(driver)
if like_btn and like_btn.is_displayed():
log.info(f'is like btn displayed? : {like_btn.is_displayed()}')
log.info('scrolling into view')
like_btn.location_once_scrolled_into_view
log.info(f'is enabled: {like_btn.is_enabled()}')
ib.click_element(driver, like_btn, 'like button')
else:
log.info('post not liked.')
def like_multiple_posts(driver, posts_to_like:int = 1):
log.info('liking multiple posts')
while (posts_to_like > 0):
like_post(driver)
driver.get('https://www.instagram.com/')
ib.random_time()
posts_to_like -= 1
def main():
ib.start_end_log(__file__)
driver = ib.login_with_cookies()
like_multiple_posts(driver, posts_to_like=4)
ib.save_cookies(driver)
ib.close_shop(driver)
if __name__ == "__main__":
main()
ib.start_end_log(__file__, end_log=True)