gpt4 book ai didi

Python Selenium 自动关注 Instagram

转载 作者:行者123 更新时间:2023-12-05 07:31:15 28 4
gpt4 key购买 nike

这个脚本在 Instagram 上没有关注,为什么?

import time
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome('./chromedriver')
"GO INSTAGRAM PAGE FOR LOGIN"
browser.get('https://www.instagram.com/accounts/login/?hl=it')

sleep(2)
"ID AND PASSWORD"
elem = browser.find_element_by_name("username").send_keys('id')
elem = browser.find_element_by_name("password").send_keys('password')
"CLICK BUTTON AND OPEN INSTAGRAM"

good_elem = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/span/button').click()

sleep(2)
browser.get("https://www.instagram.com")

"GO TO PAGE FOR FOLLOW"
browser.get("https://www.instagram.com/test/")
time.sleep(30)
"FOLLOW (DON'T WORK)"

follow = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/header/section/div[1]/span/span[1]/button').click()

最佳答案

点击元素时需要使用ActionChains。所以你的代码将是这样的:

good_elem = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/span/button')
ActionChains(browser).move_to_element(good_elem).click().perform()

对于跟随按钮,代码将是这样的:

follow = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/header/section/div[1]/span/span[1]/button')
ActionChains(browser).move_to_element(follow).click().perform()

关于Python Selenium 自动关注 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51916961/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com