python - 卡在这里制作 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()
在这段代码中,我通常模拟一个普通人跟随另一个人所做的事情。我想关注页面的每个关注者。我整天都在想;但是找不到任何算法。
有一些好主意,但刚刚意识到我不知道如何向下滚动到列表末尾以获取整个列表。你能帮我吗?(如果你不明白,请尝试运行代码,然后提取关注者列表。)
解决方案
首先,您需要获取关注某人的用户列表,然后您只需在循环中执行相同的代码。您可以将用户分开,也可以在 selenium 中。然后在 Ex 中运行跟踪给定人所需的代码。一个 for 循环。第六步:盈利
推荐阅读
- c# - 如何通过 Gstreamer-sharp 获取 Gstreamer 跟踪器消息?
- google-colaboratory - 在完成所有 epoch 之前,Google Colab Pro+ 的培训就停止了
- vue.js - “内容”组件已注册但未使用
- angular - 更新图像 url 时未删除 Swiper 预加载微调器(加载器)
- module - 配置 mod_register:在 ejabberd 21.07 版本中让我非常头疼
- python - 将日期时间四舍五入到最接近的秒数,而不是返回四舍五入到天的日期
- javascript - React Native - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created
- numpy - 当 lambda 函数的求积中的值很复杂时,在哪里可以要求 `sympy` 返回一个浮点数?
- python - 如何避免在内部 pythonical 样式循环中调用相同的函数
- c++ - 我想为一个 Arduino 项目编写一个队列类,但是如果我尝试将所有内容都设置为 0,它将不起作用,并且我无法遍历所有插槽