代码之家  ›  专栏  ›  技术社区  ›  gomathi subramanian

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

  •  -3
  • gomathi subramanian  · 技术社区  · 7 年前

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

    2 回复  |  直到 7 年前
        1
  •  5
  •   JChris    7 年前

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

    Facebook SDK for Python

    Python Social Auth documentation

    Facebook OAuth 2 Tutorial

        2
  •  1
  •   undetected Selenium    7 年前

    自动化 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