首先,我想說這是一個個人腳本,我是唯一會運行它的人。
我正在撰寫一個生產力程式,該程式會在特定時間阻止應用程式運行,chrome 就是其中之一。但是,我每天都會進行大量網頁抓取,因此我需要在代碼運行時將 chromedriver 列入“白名單”,以免關閉。
這就是我使用它的方式:
import subprocess
imgNames = ["Chrome.exe"] # There are several processes on this list, not only chrome.
for img in imgNames:
subprocess.call(['taskkill', '/F', '/IM', img], shell=True)
由于 chromedriver 具有相同的 .exe 名稱,我在想可能有一種方法可以更改行程名稱,或者可能有其他方法來識別它,因此它在塊會話期間保持打開狀態。
uj5u.com熱心網友回復:
您可以采用如下策略whilelist_process從整個串列中排除串列total_processes:
whilelist_process = "chromedriver.exe"
total_processes = ["Chrome.exe", ...] # There are several processes on this list, not only chrome.
kill_processes = [x for x in total_processes if x != whilelist_process]
for proc in kill_processes:
subprocess.call(['taskkill', '/F', '/IM', proc], shell=True)
uj5u.com熱心網友回復:
對于未來面臨同樣問題的任何人:這可能不是您期望的答案,但我最終使用了 Firefox 的 geckodriver 而不是 chromedriver,現在我能夠殺死 chromedriver 并且仍然打開了 selenium 瀏覽器,而其余部分則得到阻止。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/376551.html
