我想使程序实现无限执行,而不是根据条件进行工作

问题描述 投票:0回答:1

我有一个针对特定标签的python自动化程序,通过指定要在标签上喜欢的照片数量来运行代码,我想使程序自从添加到标签以来自动检测新帖子并喜欢它,而无需单击已经喜欢的照片(“重构”)

这是我的代码:

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

class InstagramBot:
    def __init__(self,username,password):
        self.username = username
        self.password = password
        self.bot = webdriver.Chrome(executable_path=('C:/chwd/chromedriver.exe'))

    def login(self):
        bot = self.bot
        bot.get('https://www.instagram.com/accounts/login/')
        time.sleep(3)
        email = bot.find_element_by_name('username').send_keys(self.username)
        password = bot.find_element_by_name('password').send_keys(self.password + Keys.RETURN)

        time.sleep(3)

    def searchHashtag(self,hashtag):
        bot = self.bot

        bot.get('https://www.instagram.com/explore/tags/' + hashtag)

    def likePhotos(self,amount):
        bot = self.bot

        bot.find_element_by_class_name('v1Nh3').click()

        i = 1
        while i <= amount:
            time.sleep(1)
            bot.find_element_by_class_name('fr66n').click()
            bot.find_element_by_class_name('coreSpriteRightPaginationArrow').click()
            time.sleep(1)

            i += 1







insta = InstagramBot('username', 'password')
insta.login()
insta.searchHashtag('likemyaccnow')
insta.likePhotos(3)
python selenium artificial-intelligence
1个回答
0
投票
我不确定我是否理解您的问题,但是如果您只想看程序以前从未见过的图片,则必须将其保存到json文件或保存下来,以记住已经看到的文件。进入RAM(重新启动程序后将重置)。但是为了保存图像,您必须区分照片,您可以查看图像的ID(如果存在),还可以查看日期。快乐编码
© www.soinside.com 2019 - 2024. All rights reserved.