【发布时间】:2022-01-04 12:22:37
【问题描述】:
我目前正在制作 Python Selenium Instagram 机器人,但刚刚遇到了一个简单但愚蠢的问题。我想知道为什么这行代码不会执行它的目的,即按下您刚登录 Instagram 后弹出的 Instagram DM 按钮按钮。我也在寻找一个真正执行其目的的选项,希望是一个 xpath 选项。
go_to_dm = driver.find_element_by_xpath(
"/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[2]/a/svg")
go_to_dm.click()
对于那些感兴趣的人,这里是完整的代码,除了最后一行之外,一切正常。
from selenium import webdriver
from time import sleep
from selenium import webdriver
username = ""
password = ""
ChromePath = (r"C:\Users\04fean90\OneDrive - Kungsbacka kommun\Dokument\chromedriver_win32\chromedriver.exe")
driver = webdriver.Chrome(executable_path=ChromePath)
driver.get("https://instagram.com/accounts/login")
sleep(1)
cookie_button = driver.find_element_by_xpath("//button[text()='Accept All']")
cookie_button.click()
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[1]/div/label/input").send_keys(username)
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[2]/div/label/input").send_keys(password)
sleep(5)
login_button = driver.find_element_by_xpath("//button[@type='submit']")
login_button.click()
sleep(10)
# not now
save_login_info_button = driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/div/div/div/button")
save_login_info_button.click()
driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click()
sleep(10)
go_to_dm = driver.find_element_by_xpath(
"/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[2]/a/svg")
go_to_dm.click()
【问题讨论】:
标签: python selenium selenium-webdriver xpath instagram