0

this is my code which right now only opens facebook login page but i want from my code to login in facebook.How can i do that?can you help me please?

import webbrowser

a_website = "https://www.google.com"

driver = webbrowser.open_new('https://www.facebook.com/?_rdc=2&_rdr')

username = ''
password = ''

driver.find_element_by_id('email').send_keys(username)
driver.find_element_by_id('pass').send_keys(password)
driver.find_element_by_id('loginbutton').click()
  • 1
    Is webbrowser selenium? – Matthew Gaiser Jan 21 '20 at 19:36
  • 1
    @MatthewGaiser I'm assuming OP is confusing the built-in [webbrowser library](https://docs.python.org/3/library/webbrowser.html) (which is really not very full-featured) with Selenium. They appear to be using commands that don't exist in webbrowser, but do in Selenium, without importing it. OP, please clarify your code – G. Anderson Jan 21 '20 at 19:41
  • 1
    Does this answer your question? [Login to Facebook using python requests](https://stackoverflow.com/questions/21928368/login-to-facebook-using-python-requests) – FredrikHedman Jan 21 '20 at 19:58
  • 1
    Facebook doesn't allow you to interact automatically with facebook.com. Use the API. – WizKid Jan 21 '20 at 20:28

1 Answers1

2

Use webdriver not webbrowser. Just changing your code to use that instead fixes your problem. The full code is below.

from selenium import webdriver
a_website = "https://www.google.com"

driver = webdriver.Chrome()
driver.get('https://www.facebook.com/?_rdc=2&_rdr')

username = 'aaaaaaaaa'
password = 'aaaaaaaaaaaaa'

driver.find_element_by_id('email').send_keys(username)
driver.find_element_by_id('pass').send_keys(password)
driver.find_element_by_id('loginbutton').click()
Matthew Gaiser
  • 4,558
  • 1
  • 18
  • 35