from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
dc = DesiredCapabilities.CHROME
dc['goog:loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=dc)
driver.implicitly_wait(30)
for entry in driver.get_log('browser'):
print(entry)
driver.quit()
我运行了上面的代码,但在 pycharm 中出现了以下 2 个错误
in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
在处理上述异常的过程中,又发生了一个异常:
in start raise WebDriverException(selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
答案 0 :(得分:0)
基本上它会查找 chrome webdriver 可执行文件,您可以在此处找到并下载:https://chromedriver.chromium.org/ 有两种解决方案:
driver = webdriver.Chrome(desired_capabilities=dc, executable_path = PATH_TO_WEBDRIVER)
答案 1 :(得分:0)
我知道一个很好的做法:“导入记录器”,但我会建议一个解决方案
import time
time_at_run_script=time.time()
driver.get('https://httpbin.org')
# ... code script ...
print([
entry
for entry in driver.get_log("browser")
if entry["timestamp"] > time_at_run_script
])