chrome的无头模式
from selenium import webdriver
import time
import os,platform
from selenium.webdriver.chrome.options import Options
if platform.system() =="Windows":
os.system("taskkill -im chrome* -f") # 把chrome开头的进程都杀掉
else:
os.system("killall -9 chrome*")
options = Options()
options.add_argument('--headless') # linux下的无头模式
driver = webdriver.Chrome(chrome_options=options) # 注意传参参数
driver.get("https://www.baidu.com/")
driver.maximize_window()
print(driver.current_url)
print(driver.title)
time.sleep(3)
driver.save_screenshot("./wutou.png")
driver.quit()
Firefox 的 headless
from selenium import webdriver
import time
import os,platform
from selenium.webdriver.firefox.options import Options
if platform.system() =="Windows":
os.system("taskkill -im chrome* -f") # 把chrome开头的进程都杀掉
else:
os.system("killall -9 chrome*")
options = Options()
options.headless = True # linux下的无头模式
driver = webdriver.Firefox(firefox_options=options)
driver.get("https://www.baidu.com/")
driver.maximize_window()
print(driver.current_url)
print(driver.title)
time.sleep(3)
driver.save_screenshot("./wutou.png")
driver.quit()
网友评论