提问人:ddadf 提问时间:8/7/2023 最后编辑:ddadf 更新时间:11/22/2023 访问量:163
Selenium Bot Auto 在 Instagram 上关注其他人
selenium bot auto follow others follower on instagram
问:
此代码应该关注 Instagram 上的其他关注者,但是当我运行代码 Instagram 登录时,机器人会自行注销,所以我到处搜索修复方法,没有任何效果 因此,要运行它,您需要添加您的 chrome 路径和您想要关注其关注者的 ACC (SIMILAR_ACCOUNT),并输入您的通行证和用户,以便它自己登录
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.webdriver.chrome.options import Options
CHROME_DRIVER_PATH = ""
#put the acc that wou wanna follow his followers
SIMILAR_ACCOUNT = "chefsteps"
EMAIL = ""
PASSWORD = ""
class InstaFollower:
def __init__(self, path):
s = Service(path)
self.driver = webdriver.Chrome(service=s)
def login(self):
self.driver.get("https://www.instagram.com/accounts/login/")
time.sleep(2)
email = self.driver.find_element(By.NAME, "username")
email.send_keys(EMAIL)
password = self.driver.find_element(By.NAME, "password")
password.send_keys(PASSWORD)
time.sleep(2)
password.send_keys(Keys.ENTER)
time.sleep(5)
not_now_popup = self.driver.find_element(By.CSS_SELECTOR, ".cmbtv .sqdOP")
not_now_popup.click()
time.sleep(3)
close_popup = self.driver.find_element(By.CSS_SELECTOR, ".mt3GC .HoLwm ")
close_popup.click()
def find_followers(self):
time.sleep(3)
self.driver.get(f"https://www.instagram.com/{SIMILAR_ACCOUNT}/")
time.sleep(3)
followers = self.driver.find_element(By.PARTIAL_LINK_TEXT, 'followers')
followers.click()
time.sleep(3)
followers_popup = self.driver.find_element(By.XPATH, '/html/body/div[6]/div/div/div[2]')
for i in range(10):
self.driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", followers_popup)
time.sleep(3)
def follow(self):
all_buttons = self.driver.find_elements(By.CSS_SELECTOR, "li button")
for button in all_buttons:
try:
button.click()
except ElementClickInterceptedException:
cancel_button = self.driver.find_element(By.XPATH, "/html/body/div[7]/div/div/div/div[3]/button[2]")
cancel_button.click()
finally:
time.sleep(2)
bot = InstaFollower(CHROME_DRIVER_PATH)
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
bot.login()
bot.find_followers()
bot.follow()
答: 暂无答案
评论