- Python Selenium 自動化登入FB
展示圖:
- from selenium import webdriver
- from bs4 import BeautifulSoup
- import time
- # 關閉通知
- options = webdriver.ChromeOptions()
- prefs = {
- 'profile.default_content_setting_values':
- {
- 'notifications': 2
- }
- }
- options.add_experimental_option('prefs', prefs)
- options.add_argument("disable-infobars")
- # 打啟動selenium 務必確認driver 檔案跟python 檔案要在同個資料夾中
- driver = webdriver.Chrome(options=options)
- email_address = "xxx"
- password = "xxx"
- #driver = webdriver.Chrome("./chromedriver")
- #driver.implicitly_wait(10)
- url = "https://www.facebook.com/"
- driver.get(url)
- email = driver.find_element_by_css_selector("#email")
- email.send_keys(email_address)
- time.sleep(0.5)
- passwd = driver.find_element_by_css_selector("#pass")
- passwd.send_keys(password)
- time.sleep(0.5)
- button =driver.find_element_by_css_selector("button[name='login']")
- button.click()
- time.sleep(7)
- Python, Selenium, 自動化, FaceBook