我正在编写一些硒代码来导航 Facebook。
import os
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
def driver():
global driver
driver = webdriver.Chrome("chromedriver.exe", chrome_options=chrome_options)
driver.get("https://facebook.com")
def chrome_options():
global chrome_options
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--profile-directory=Default')
# chrome_options.add_argument("--user-data-dir=chrome-data")
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument('disable-infobars')
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
def actions():
global actions
actions = ActionChains(driver)
def login():
try:
# I use environment veriable base on this tutorials https://www.youtube.com/watch?v=IolxqkL7cD8
username = os.environ.get('my_facebook_username')
password = os.environ.get('my_facebook_password')
driver.find_element_by_name("email").send_keys(username) …Run Code Online (Sandbox Code Playgroud)