Skip to content

Instantly share code, notes, and snippets.

@linzino7
Created July 1, 2020 09:24
Show Gist options
  • Save linzino7/7df4f034d08b804d92b12e80ed04609a to your computer and use it in GitHub Desktop.
Save linzino7/7df4f034d08b804d92b12e80ed04609a to your computer and use it in GitHub Desktop.
from selenium import webdriver
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)
driver.get("https://www.facebook.com/")
time.sleep(4)
#輸入email
context = driver.find_element_by_css_selector('#email')
context.send_keys("youremail@gmail.com") '''記得修改'''
time.sleep(0.5)
#輸入password
context = driver.find_element_by_css_selector('#pass')
context.send_keys("password")'''記得修改'''
time.sleep(0.5)
#
commit = driver.find_element_by_css_selector('#loginbutton')
commit.click()
time.sleep(7)
# 抓第一筆貼文
getcontext = driver.find_element_by_css_selector('.userContentWrapper')
print(getcontext.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment