mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
2.7.1修复使用Anaconda中关闭driver时的小问题
This commit is contained in:
parent
caca993c6a
commit
ee61f1d8bd
@ -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:
|
||||
|
@ -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: 是否成功
|
||||
|
@ -1,4 +1,4 @@
|
||||
# v2.7.0
|
||||
# v2.7.1
|
||||
|
||||
- DriverPage
|
||||
|
||||
|
2
setup.py
2
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.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user