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

时间:2018-03-14 10:44:35

标签: python python-3.x selenium selenium-webdriver user-input

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

2 个答案:

答案 0 :(得分:2)

你应该使用Facebook OAuth API,永远不要硬编码密码,一些参考:

Facebook SDK for Python

Python Social Auth documentation

Facebook OAuth 2 Tutorial

答案 1 :(得分:0)

要自动执行 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