Skip to content

Commit

Permalink
修改注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Feb 9, 2022
1 parent 1a29e7c commit eebda16
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions feapder/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit eebda16

Please sign in to comment.