---------------------- 谷歌无头浏览器 -----------------------------
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
创建一个参数对象,用来控制chrome以无界面模式打开
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
创建浏览器对象
driver = webdriver.Chrome(chrome_options=chrome_options)
driver = webdriver.Chrome()
driver.implicitly_wait(10)
wait = WebDriverWait(driver, 10, 0.5)
driver.get("https://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Na_years")
driver.find_element_by_id("su").click()
wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'Na_years - 博客园'))).click()
time.sleep(3)
driver.quit()