diff --git a/feapder/utils/webdriver.py b/feapder/utils/webdriver.py index 3e56955e..e09e690d 100644 --- a/feapder/utils/webdriver.py +++ b/feapder/utils/webdriver.py @@ -72,7 +72,7 @@ def __init__( window_size: # 窗口大小 executable_path: 浏览器路径,默认为默认路径 xhr_url_regexes: 拦截xhr接口,支持正则,数组类型 - download_path: 如果指定,不再出现“保留”“放弃”提示,仅对Chrome有效 + download_path: 文件下载保存路径;如果指定,不再出现“保留”“放弃”提示,仅对Chrome有效 **kwargs: """ self._load_images = load_images @@ -87,7 +87,9 @@ def __init__( self._download_path = download_path if self._xhr_url_regexes and driver_type != WebDriver.CHROME: - raise Exception("xhr_url_regexes only support by chrome now! eg: driver_type=WebDriver.CHROME") + raise Exception( + "xhr_url_regexes only support by chrome now! eg: driver_type=WebDriver.CHROME" + ) if driver_type == WebDriver.CHROME: self.driver = self.chrome_driver() @@ -214,8 +216,8 @@ def chrome_driver(self): if self._download_path: os.makedirs(self._download_path, exist_ok=True) prefs = { - 'download.prompt_for_download': False, - 'download.default_directory': self._download_path + "download.prompt_for_download": False, + "download.default_directory": self._download_path, } chrome_options.add_experimental_option("prefs", prefs) @@ -249,15 +251,15 @@ def chrome_driver(self): driver.execute_cdp_cmd( "Page.addScriptToEvaluateOnNewDocument", {"source": js} ) - + if self._download_path: - driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command') + driver.command_executor._commands["send_command"] = ( + "POST", + "/session/$sessionId/chromium/send_command", + ) params = { - 'cmd': 'Page.setDownloadBehavior', - 'params': { - 'behavior': 'allow', - 'downloadPath': self._download_path - } + "cmd": "Page.setDownloadBehavior", + "params": {"behavior": "allow", "downloadPath": self._download_path}, } driver.execute("send_command", params)