※ 引述《Sagbtoautumn (小饅頭)》之銘言:
: 各位前輩大家好,小弟前一陣子也自己練習網頁爬蟲...
: 但遇到一個問題想請教各位前輩.
: 網路上很多教學會開一個web browser,然後再針對網頁物件作操作.
: (例如開啟網頁,然後尋找網頁中某個按鍵的name,然後再對其做相關操作.)
: EXECurPath = os.path.dirname(os.path.abspath( _file_ ))
: Chrome_Path = EXECurPath + "\geckodriver\chromedriver.exe"
: browser = webdriver.Chrome(Chrome_Path)
: browser.get("https://www.google.com.tw/")
: ...爬蟲code省略...
: 但這都是會開啟web browser.因為某些需求,是否能不開啟web browser視窗.
: 依然可以達到爬蟲效果呢?
: 請問有辦法背景執行而不彈出cmd視窗嗎?
: 因為當彈出web browser時候影響其他在執行的工作.
: (當然有人會給建議,將視窗長與寬設定很小或是產生cmd視窗在邊緣...
: 但目前可能不朝這兩個方向)
: 希望各位前輩或高手能給小弟我一個方向,在此先說聲感謝您了.
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.221.35.72
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1550721056.A.8FE.html
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument('--headless')
opts.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(driver, chrome_options=opts)