我有一个针对特定标签的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)