mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
click.to_download()增加timeout参数;完善找chrome路径逻辑;调整quit()逻辑
This commit is contained in:
parent
70243a1fd1
commit
038d837dda
@ -316,14 +316,20 @@ def get_chrome_path(ini_path):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# -----------从注册表中获取--------------
|
# -----------从注册表中获取--------------
|
||||||
import winreg
|
from winreg import OpenKey, EnumValue, CloseKey, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ
|
||||||
try:
|
try:
|
||||||
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
|
key = OpenKey(HKEY_CURRENT_USER,
|
||||||
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
||||||
reserved=0, access=winreg.KEY_READ)
|
reserved=0, access=KEY_READ)
|
||||||
k = winreg.EnumValue(key, 0)
|
k = EnumValue(key, 0)
|
||||||
winreg.CloseKey(key)
|
CloseKey(key)
|
||||||
|
if k[1]:
|
||||||
|
return k[1]
|
||||||
|
key = OpenKey(HKEY_LOCAL_MACHINE,
|
||||||
|
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
||||||
|
reserved=0, access=KEY_READ)
|
||||||
|
k = EnumValue(key, 0)
|
||||||
|
CloseKey(key)
|
||||||
return k[1]
|
return k[1]
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -204,7 +204,12 @@ def stop_process_on_port(port, pid=None):
|
|||||||
for conn in connections:
|
for conn in connections:
|
||||||
if conn.laddr.port == int(port):
|
if conn.laddr.port == int(port):
|
||||||
try:
|
try:
|
||||||
proc.terminate()
|
# proc.terminate()
|
||||||
|
parent = proc.parent()
|
||||||
|
if parent is None:
|
||||||
|
proc.kill()
|
||||||
|
elif parent.name() == 'explorer.exe':
|
||||||
|
proc.terminate()
|
||||||
except (NoSuchProcess, AccessDenied, ZombieProcess):
|
except (NoSuchProcess, AccessDenied, ZombieProcess):
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -140,13 +140,14 @@ class Clicker(object):
|
|||||||
"""
|
"""
|
||||||
self.at(count=times)
|
self.at(count=times)
|
||||||
|
|
||||||
def to_download(self, save_path=None, rename=None, suffix=None, new_tab=False, by_js=False):
|
def to_download(self, save_path=None, rename=None, suffix=None, new_tab=False, by_js=False, timeout=None):
|
||||||
"""点击触发下载
|
"""点击触发下载
|
||||||
:param save_path: 保存路径,为None保存在原来设置的,如未设置保存到当前路径
|
:param save_path: 保存路径,为None保存在原来设置的,如未设置保存到当前路径
|
||||||
:param rename: 重命名文件名
|
:param rename: 重命名文件名
|
||||||
:param suffix: 指定文件后缀
|
:param suffix: 指定文件后缀
|
||||||
:param new_tab: 该下载是否在新tab中触发
|
:param new_tab: 该下载是否在新tab中触发
|
||||||
:param by_js: 是否用js方式点击,逻辑与click()一致
|
:param by_js: 是否用js方式点击,逻辑与click()一致
|
||||||
|
:param timeout: 等待下载触发的超时时间,为None则使用页面对象设置
|
||||||
:return: DownloadMission对象
|
:return: DownloadMission对象
|
||||||
"""
|
"""
|
||||||
if save_path:
|
if save_path:
|
||||||
@ -160,7 +161,7 @@ class Clicker(object):
|
|||||||
tab = self._ele.page._page if new_tab else self._ele.page
|
tab = self._ele.page._page if new_tab else self._ele.page
|
||||||
|
|
||||||
self.left(by_js=by_js)
|
self.left(by_js=by_js)
|
||||||
return tab.wait.download_begin()
|
return tab.wait.download_begin(timeout=timeout)
|
||||||
|
|
||||||
def to_upload(self, file_paths, by_js=False):
|
def to_upload(self, file_paths, by_js=False):
|
||||||
"""触发上传文件选择框并自动填入指定路径
|
"""触发上传文件选择框并自动填入指定路径
|
||||||
|
@ -38,7 +38,8 @@ class Clicker(object):
|
|||||||
rename: str = None,
|
rename: str = None,
|
||||||
suffix: str = None,
|
suffix: str = None,
|
||||||
new_tab: bool = False,
|
new_tab: bool = False,
|
||||||
by_js: bool = False) -> DownloadMission: ...
|
by_js: bool = False,
|
||||||
|
timeout:float=None) -> DownloadMission: ...
|
||||||
|
|
||||||
def to_upload(self, file_paths: Union[str, Path, list, tuple], by_js: bool = False) -> None: ...
|
def to_upload(self, file_paths: Union[str, Path, list, tuple], by_js: bool = False) -> None: ...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user