From ee61f1d8bde2cd1b5aab1c6d8c2ec45e0a84fcea Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 23 Jun 2022 11:30:50 +0800 Subject: [PATCH] =?UTF-8?q?2.7.1=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8Anacon?= =?UTF-8?q?da=E4=B8=AD=E5=85=B3=E9=97=ADdriver=E6=97=B6=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/common.py | 22 +++++++++++++--------- DrissionPage/drission.py | 4 ++-- docs/版本历史.md | 2 +- setup.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/DrissionPage/common.py b/DrissionPage/common.py index 2727456..16bc2e5 100644 --- a/DrissionPage/common.py +++ b/DrissionPage/common.py @@ -370,20 +370,24 @@ def get_pid_from_port(port: Union[str, int]) -> Union[str, None]: :param port: 端口号 :return: 进程id """ - from os import popen from platform import system + if system().lower() != 'windows' or port is None: + return None + + from os import popen from time import perf_counter - if system().lower() != 'windows' or port is None: - return - - process = popen(f'netstat -ano |findstr {port}').read().split('\n')[0] - - t = perf_counter() - while not process and perf_counter() - t < 5: + try: # 避免Anaconda中可能产生的报错 process = popen(f'netstat -ano |findstr {port}').read().split('\n')[0] - return process.split(' ')[-1] or None + t = perf_counter() + while not process and perf_counter() - t < 5: + process = popen(f'netstat -ano |findstr {port}').read().split('\n')[0] + + return process.split(' ')[-1] or None + + except AttributeError: + return None def get_usable_path(path: Union[str, Path]) -> Path: diff --git a/DrissionPage/drission.py b/DrissionPage/drission.py index b6f1609..f73b94d 100644 --- a/DrissionPage/drission.py +++ b/DrissionPage/drission.py @@ -504,7 +504,7 @@ def _create_driver(chrome_path: str, driver_path: str, options: Options) -> WebD def _get_chrome_hwnds_from_pid(pid) -> list: - # 通过PID查询句柄ID + """通过PID查询句柄ID""" try: from win32gui import IsWindow, GetWindowText, EnumWindows from win32process import GetWindowThreadProcessId @@ -524,7 +524,7 @@ def _get_chrome_hwnds_from_pid(pid) -> list: def _kill_progress(pid: str = None, port: int = None) -> bool: - """获取端口号第一条进程的pid \n + """关闭浏览器进程 \n :param pid: 进程id :param port: 端口号,如没有进程id,从端口号获取 :return: 是否成功 diff --git a/docs/版本历史.md b/docs/版本历史.md index b0f5163..4e7a075 100644 --- a/docs/版本历史.md +++ b/docs/版本历史.md @@ -1,4 +1,4 @@ -# v2.7.0 +# v2.7.1 - DriverPage diff --git a/setup.py b/setup.py index fa552ef..48d5c72 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="2.7.0", + version="2.7.1", author="g1879", author_email="g1879@qq.com", description="A module that integrates selenium and requests session, encapsulates common page operations.",