小编典典

如何在python自动化期间提供凭据作为用户输入运行时?

python

如何在不对用户名和密码进行硬编码的情况下自动执行Facebook登录?


阅读 264

收藏
2021-01-20

共1个答案

小编典典

要自动进行 Facebook登录 而无需对 用户名密码 进行硬编码,可以使用此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
2021-01-20