• Python Selenium 自動化登入FB
  • 推文至Facebook  
  • 展示圖:

    Python Selenium 自動化登入 FB

    Python Selenium 自動化登入 FB

    1. from selenium import webdriver
    2. from bs4 import BeautifulSoup
    3. import time
    4.  
    5. # 關閉通知
    6. options = webdriver.ChromeOptions()
    7. prefs = {
    8.     'profile.default_content_setting_values':
    9.         {
    10.             'notifications': 2
    11.         }
    12. }
    13. options.add_experimental_option('prefs', prefs)
    14. options.add_argument("disable-infobars")
    15.  
    16. # 打啟動selenium 務必確認driver 檔案跟python 檔案要在同個資料夾中
    17. driver = webdriver.Chrome(options=options)
    18.  
    19. email_address = "xxx"
    20. password = "xxx"
    21. #driver = webdriver.Chrome("./chromedriver")
    22. #driver.implicitly_wait(10)
    23. url = "https://www.facebook.com/"
    24. driver.get(url)
    25.  
    26. email = driver.find_element_by_css_selector("#email")
    27. email.send_keys(email_address)
    28. time.sleep(0.5)
    29.  
    30. passwd = driver.find_element_by_css_selector("#pass")
    31. passwd.send_keys(password)
    32. time.sleep(0.5)
    33.  
    34. button =driver.find_element_by_css_selector("button[name='login']")
    35. button.click()
    36. time.sleep(7)
  • 標籤:Python, Selenium, 自動化, FaceBook,
NetYea 客服 NetYea 客服
NetYea 客服

Python Selenium 自動化登入FB -