首页 > 解决方案 > 卡在这里制作 Instagram 机器人

问题描述

这是我的代码:

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

# loading the webpage
browser = webdriver.Chrome()
browser.get("https://instagram.com")
time.sleep(1)

# finding essential requirements
user_name = browser.find_element_by_name("username")
password = browser.find_element_by_name("password")
login_button = browser.find_element_by_xpath("//button [@type = 'submit']")

# filling out the user name box
user_name.click()
user_name.clear()
user_name.send_keys("username")

# filling out the password box
password.click()
password.clear()
password.send_keys("password")

# clicking on the login button
login_button.click()
time.sleep(3)

# information save permission denial
not_now_button = browser.find_element_by_xpath("//button [@class = 'sqdOP yWX7d    y3zKF     ']")
not_now_button.click()
time.sleep(3)

# notification permission denial
not_now_button_2 = browser.find_element_by_xpath("//button [@class = 'aOOlW   HoLwm ']")
not_now_button_2.click()
time.sleep(3)

# finding search box and searching + going to the page
search_box = browser.find_element_by_xpath('//input [@placeholder="Search"]')
search_box.send_keys("sb else's page")
time.sleep(3)
search_box.send_keys(Keys.RETURN)
search_box.send_keys(Keys.RETURN)
time.sleep(3)

# opening ((followers)) list
followers = browser.find_element_by_xpath('//a [@class="-nal3 "]')
followers.click()
time.sleep(10)

# following each follower
follower = browser.find_elements_by_xpath('//button [@class="sqdOP  L3NKy   y3zKF     "]')


browser.close()

在这段代码中,我通常模拟一个普通人跟随另一个人所做的事情。我想关注页面的每个关注者。我整天都在想;但是找不到任何算法。


有一些好主意,但刚刚意识到我不知道如何向下滚动到列表末尾以获取整个列表。你能帮我吗?(如果你不明白,请尝试运行代码,然后提取关注者列表。)

标签: pythonseleniuminstagram

解决方案


首先,您需要获取关注某人的用户列表,然后您只需在循环中执行相同的代码。您可以将用户分开,也可以在 selenium 中。然后在 Ex 中运行跟踪给定人所需的代码。一个 for 循环。第六步:盈利


推荐阅读