How to provide credentials as user input runtime d

2019-02-21 06:43发布

How to automate the Facebook login without hard-coding my username and password?

2条回答
放荡不羁爱自由
2楼-- · 2019-02-21 07:07

To automate the Facebook Login without hard-coding the username and password you can use the input() function to take the user input from the console as follows :

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()

Console Output :

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
查看更多
别忘想泡老子
3楼-- · 2019-02-21 07:13

You should use Facebook OAuth API, never hard-code password, some references:

Facebook SDK for Python

Python Social Auth documentation

Facebook OAuth 2 Tutorial

查看更多
登录 后发表回答