python - 在 selenium 中找不到/单击特定按钮(instagram bot)
问题描述
所以我一直在尝试制作一个具有多种功能的instagram bot,例如关注/登录/取消关注/垃圾邮件。我对如何实现这些功能有一些想法,但我在登录时遇到了困难。机器人写入用户名和密码,然后提交机器人成功登录,但是当“保存您的登录信息?” 页面出现我的机器人假设单击“不是现在”它给出错误(它找不到该按钮或无法单击)
我试图修复它,但无法提出任何解决方案。在过去的 5 天里,我一直在尝试解决此问题,请帮助我。
//需要的chrome驱动
源代码
def login():
os.system("cls")
directory= os.path.dirname(os.path.abspath(__file__))
chromedriverdirectory = os.path.join(directory, 'chromedriver.exe')
driver = webdriver.Chrome(executable_path = chromedriverdirectory)
os.system("cls")
driver.get("https://instagram.com")
time.sleep(5)
driver.find_element_by_xpath(("//input[@name=\"username\"]"))\
.send_keys((username))
os.system("cls")
driver.find_element_by_xpath(("//input[@name=\"password\"]"))\
.send_keys((password))
os.system("cls")
driver.find_element_by_xpath('//button[@type="submit"]')\
.click()
os.system("cls")
time.sleep(4)
driver.find_element_by_xpath('//button[contains(text(), "Not Now")]').click()
完整代码如下
解决方案
推荐阅读
- rust - 重新打开 AboutDialog 显示一个空白对话框
- swift - 当应用程序安装在设备上时如何在 iOS 中执行功能
- algorithm - 有向循环图如何具有“最远节点”?
- nix - 由于缺少 nixos 通道,nixos-rebuild 无法构建
- java - 当从同一个变量初始化一个新对象时,前一个对象是否会被删除?
- javascript - 单击时过滤具有多个条件的数组(复选框元素)
- css - 你如何让 CSS Isolation 在引用的项目上工作?
- ios - 无法将变量的值从一个类传递给Objective c中的另一个类
- python - QGraphicsscene.itemAt() 方法抛出错误
- django - 带有mongodb的Django rest-framework不创建自动字段主键ID