-3

The problem is that it dosen't like the posts.

I have tried difrend methods like tag name


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time


    def like_photo(self):
        driver = self.driver
        driver.get("https://www.instagram.com")
        time.sleep(1)
        for i in range(1, 4):
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            time.sleep(2)

        # find all the heart links
        hrefs = driver.find_elements_by_xpath("//span[@aria-label='Synes godt om']")
        pic_hrefs = [elem.get_attribute('href') for elem in hrefs]
        pic_hrefs = [href for href in pic_hrefs]
        print(' Photos ' + str(len(pic_hrefs)))

        for _ in pic_hrefs:
            driver.get("https://www.instagram.com")
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            try:
                like_button = lambda: driver.find_elements_by_xpath("//span[@aria-label='Synes godt om']")
                like_button.click()
                time.sleep(18)
            except Exception as e:
                time.sleep(1)


nameIG = InstagramBot(username, password)
nameIG.login()
nameIG.like_photo()


It dosent like any post the output is just: Photos 4

Process finished with exit code 0

LazyCoder
  • 1,267
  • 5
  • 17
sofus
  • 1
  • 2
  • Note that a good Stack Overflow question is about a *specific* problem, with only the shortest code needed to isolate that problem. Thus, in an ideal world, one isolates the specific XPath query that isn't working, and writes the shortest test harness that someone else can run to see for themselves that it doesn't work, before asking the question. – Charles Duffy Jul 28 '19 at 15:42

1 Answers1

0

exit code 0 means your code is running with no error. However, there's still a problem.

To see if there are actual errors in your code, change the exception actions.

    except Exception as e:
        print(e)  # shows actual error

Try this:

like_buttons = driver.find_elements_by_xpath(some_xpath_to_buttons)  # list of WebElements
for button in like_buttons:
    button.click()
    time.sleep(18)
ugatah
  • 26
  • 4
  • After entering the second code:Message: element click intercepted: Element is not clickable at point (634, 5). Other element would receive the click:
    ...
    (Session info: chrome=75.0.3770.142) x 10
    – sofus Jul 28 '19 at 10:23
  • Open your browsers console and check if the xpath is finding what you want. This article should help get you started: https://stackoverflow.com/questions/22571267/how-to-verify-an-xpath-expression-in-chrome-developers-tool-or-firefoxs-firebug. Once you have the right xpath, use it. – ugatah Jul 28 '19 at 15:42
  • As you can see here: https://photos.app.goo.gl/vjuwtcGmTJ3uiLtJA the robot can see the button but can't click it. And more evedince that it isent clickeble if the error code: Message: element click intercepted: Element is not clickable at point (69, 20). Other element would receive the click:
    ...
    (Session info: chrome=75.0.3770.142)
    – sofus Jul 28 '19 at 18:41