From 4248fe3378ea3dbf60533655b335c3bba1918842 Mon Sep 17 00:00:00 2001 From: XavierMarchena Date: Tue, 19 Dec 2023 19:30:22 -0600 Subject: [PATCH 1/2] Update xpaths --- insta-bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/insta-bot.py b/insta-bot.py index a089c76..66bb484 100644 --- a/insta-bot.py +++ b/insta-bot.py @@ -73,7 +73,7 @@ # Click first thumbnail to open first_thumbnail = browser.find_element_by_xpath( - "/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div[1]/div[2]") + "/html/body/div[2]/div/div/div[2]/div/div/div[1]/div[1]/div[2]/section/main/article/div/div/div/div[1]/div[1]") first_thumbnail.click() @@ -83,11 +83,11 @@ # Check if the post is already liked # If not, then like, comment, and go to next post try: - browser.find_element_by_xpath("//button/div/*[*[local-name()='svg']/@aria-label='Unlike']/*") + browser.find_element_by_xpath("//div[@role='button']/following::section[1]/span[1]/div[@role='button']/div/span/descendant::*[@aria-label='Unlike']") logger.info("Already liked this post") except Exception: # Like - browser.find_element_by_xpath("//button/div/*[*[local-name()='svg']/@aria-label='Like']/*").click() + browser.find_element_by_xpath("//div[@role='button']/following::section[1]/span[1]/div[@role='button']/div/span/descendant::*[@aria-label='Like']").click() logger.info("Liked") likes += 1 @@ -96,8 +96,8 @@ if do_i_comment == 1: try: # Comment - browser.find_element_by_xpath("//div/form").click() - comment = browser.find_element_by_xpath("//form/textarea") + browser.find_element_by_xpath("//article/descendant::section[3]/div/form").click() + comment = browser.find_element_by_xpath("//article/descendant::section[3]/div/form/div/textarea") sleep(wait_to_comment) From fec0e1abcc03aa45dcb8d9f2587c30bcdb0a1d22 Mon Sep 17 00:00:00 2001 From: XavierMarchena Date: Tue, 19 Dec 2023 19:44:30 -0600 Subject: [PATCH 2/2] Simplify xpath --- insta-bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/insta-bot.py b/insta-bot.py index 66bb484..e4afff9 100644 --- a/insta-bot.py +++ b/insta-bot.py @@ -83,11 +83,11 @@ # Check if the post is already liked # If not, then like, comment, and go to next post try: - browser.find_element_by_xpath("//div[@role='button']/following::section[1]/span[1]/div[@role='button']/div/span/descendant::*[@aria-label='Unlike']") + browser.find_element_by_xpath("//div[@role='button']/div/span/descendant::*[@aria-label='Unlike']") logger.info("Already liked this post") except Exception: # Like - browser.find_element_by_xpath("//div[@role='button']/following::section[1]/span[1]/div[@role='button']/div/span/descendant::*[@aria-label='Like']").click() + browser.find_element_by_xpath("//div[@role='button']/div/span/descendant::*[@aria-label='Like']").click() logger.info("Liked") likes += 1