Python Instagram机器人程序

2024-03-28 12:31:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用python写了一个Instagram喜欢的机器人。喜欢的功能是:

喜欢照片

    unique_photos = len(pic_hrefs)
    for pic_href in pic_hrefs:
        driver.get(pic_href)
        time.sleep(2)

        try:
          time.sleep(random.randint(4, 15))
          like_button = lambda: driver.find_element_by_class_name("_8-yf5 ").click()
          like_button().click()

          for second in reversed(range(0, random.randint(18, 28))):
             print_same_line("#" + hashtag + ': unique photos left: ' + str(unique_photos)
                            + " | Sleeping " + str(second))
             time.sleep(2) 
        except Exception as e:
          time.sleep(2)
        unique_photos -= 1

我现在想添加一个具有相同限制的Likecount。我还想检查一下我是否已经喜欢了一张照片,然后跳过那张。我该怎么做


Tags: infortimedriverbuttonsleeprandom照片
1条回答
网友
1楼 · 发布于 2024-03-28 12:31:41

是的,咏叹调的标签改变了。我是这样试的:

like_xpath ='//span[@aria-label="Gefällt mir"]'
        liked_xpath = '//span[@aria-label="Gefällt mir nicht mehr"]'
        unliked = self.driver.find_elements_by_xpath(like_xpath)
        liked = self.driver.find_elements_by_xpath(liked_xpath)

如果你喜欢。。。。 但它不起作用

相关问题 更多 >