我试着用一些函数制作一个instagram机器人。它在instagram上打开,然后停止有人能给我解释一下出了什么问题并让它发挥作用吗?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
time.sleep(2)
driver.get("https://www.instagram.com/")
driver.get("https://www.instagram.com/")
time.sleep(2)
def logIn(name, password):
name = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input')
time.sleep(2)
name.send_keys(name)
time.sleep(2)
passw = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input')
time.sleep(2)
passw.send_keys(password)
time.sleep(2)
driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button/div').click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/div/div/button').click()
print("Login succsessful")
def main():
logIn(name = "accountname",password = "accountpassword")
if __name__ == "__main__":
pass
问题是,您从未实际调用过main
函数,因此它会打开浏览器并立即关闭。