在使用seleinum的時候,如果模擬谷歌或者火狐瀏覽器,出現一個界面的話太難受了所幸firefox和chrome都有了無頭模式,也就是沒有界面的瀏覽器,在內存中執行。
firefox設置:
from selenium import webdriver options = webdriver.FirefoxOptions() options.add_argument('-headless') browser = webdriver.Firefox(firefox_options=options) browser.get('https://www.cnblogs.com/xuchunlin/')
chrome設置:
Chrome_options = webdriver.ChromeOptions() Chrome_options.add_argument('-headless') drive = webdriver.Chrome(chrome_options=Chrome_options) drive.get('https://www.cnblogs.com/xuchunlin/')