Skip to content

Instantly share code, notes, and snippets.

@thanhtoan1196
Forked from south1907/login_messenger.py
Created July 15, 2020 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanhtoan1196/b9d1b9b32e412a7a7c6fb7b65b9cde66 to your computer and use it in GitHub Desktop.
Save thanhtoan1196/b9d1b9b32e412a7a7c6fb7b65b9cde66 to your computer and use it in GitHub Desktop.
Login facebook messenger and chat
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.keys import Keys
import time
email = 'youremail@gmail.com'
password = 'yourpassword'
browser = Chrome()
url = 'https://www.facebook.com/'
browser.get(url)
# nhập username, password
email_input = browser.find_element_by_xpath('//input[@type="email"]')
email_input.send_keys(email)
pass_input = browser.find_element_by_xpath('//input[@type="password"]')
pass_input.send_keys(password)
pass_input.send_keys(Keys.RETURN)
url_mes = 'https://messenger.com/'
browser.get(url_mes)
time.sleep(5)
# click vào nút cho phép đăng nhập với account facebook hiện tại
submit_input = browser.find_element_by_xpath('//button[@type="submit"]')
submit_input.click()
url_mes_account_1 = 'https://www.messenger.com/t/100037068474173'
browser.get(url_mes_account_1)
# chat tin nhắn
text = 'hi'
text_input = browser.find_element_by_xpath('//div[@role="combobox"]')
text_input.send_keys(text)
text_input.send_keys(Keys.RETURN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment