如何在不对我的用户名和密码进行硬编码的情况下自动执行Facebook登录?
答案 0 :(得分:2)
你应该使用Facebook OAuth API,永远不要硬编码密码,一些参考:
答案 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