如何在不对用户名和密码进行硬编码的情况下自动执行Facebook登录?
要自动进行 Facebook登录 而无需对 用户名 和 密码 进行硬编码,可以使用此input()功能从控制台获取 用户输入 ,如下所示:
input()
from selenium import webdriver driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe') driver.get("https://www.facebook.com/") emailid = input("What is your emailid?(Press enter at the end to continue):") driver.find_element_by_xpath("//input[@id='email']").send_keys(emailid) password = input("What is your password?(Press enter at the end to continue):") driver.find_element_by_xpath("//input[@id='pass']").send_keys("password") driver.find_element_by_xpath("//input[starts-with(@id, 'u_0_')][@value='Log In']").click()
控制台输出:
What is your emailid?(Press enter at the end to continue):gomathisubramanian@gmail.com What is your password?(Press enter at the end to continue):gomathisubramanian