seleniumChrom无头浏览器

社会主义新天地 提交于 2020-01-10 19:36:28

---------------------- 谷歌无头浏览器 -----------------------------

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()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!