mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
Compare commits
2 Commits
cfb0a6b8f6
...
038d837dda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
038d837dda | ||
|
|
70243a1fd1 |
@ -316,14 +316,20 @@ def get_chrome_path(ini_path):
|
||||
return None
|
||||
|
||||
# -----------从注册表中获取--------------
|
||||
import winreg
|
||||
from winreg import OpenKey, EnumValue, CloseKey, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ
|
||||
try:
|
||||
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
|
||||
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
||||
reserved=0, access=winreg.KEY_READ)
|
||||
k = winreg.EnumValue(key, 0)
|
||||
winreg.CloseKey(key)
|
||||
|
||||
key = OpenKey(HKEY_CURRENT_USER,
|
||||
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
||||
reserved=0, access=KEY_READ)
|
||||
k = EnumValue(key, 0)
|
||||
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]
|
||||
|
||||
except FileNotFoundError:
|
||||
|
||||
@ -204,7 +204,12 @@ def stop_process_on_port(port, pid=None):
|
||||
for conn in connections:
|
||||
if conn.laddr.port == int(port):
|
||||
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):
|
||||
pass
|
||||
except Exception as e:
|
||||
|
||||
@ -140,13 +140,14 @@ class Clicker(object):
|
||||
"""
|
||||
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 rename: 重命名文件名
|
||||
:param suffix: 指定文件后缀
|
||||
:param new_tab: 该下载是否在新tab中触发
|
||||
:param by_js: 是否用js方式点击,逻辑与click()一致
|
||||
:param timeout: 等待下载触发的超时时间,为None则使用页面对象设置
|
||||
:return: DownloadMission对象
|
||||
"""
|
||||
if save_path:
|
||||
@ -159,8 +160,8 @@ class Clicker(object):
|
||||
|
||||
tab = self._ele.page._page if new_tab else self._ele.page
|
||||
|
||||
self._ele.click(by_js=by_js)
|
||||
return tab.wait.download_begin()
|
||||
self.left(by_js=by_js)
|
||||
return tab.wait.download_begin(timeout=timeout)
|
||||
|
||||
def to_upload(self, file_paths, by_js=False):
|
||||
"""触发上传文件选择框并自动填入指定路径
|
||||
@ -169,9 +170,20 @@ class Clicker(object):
|
||||
:return: None
|
||||
"""
|
||||
self._ele.page.set.upload_files(file_paths)
|
||||
self._ele.click(by_js=by_js)
|
||||
self.left(by_js=by_js)
|
||||
self._ele.page.wait.upload_paths_inputted()
|
||||
|
||||
def for_new_tab(self, by_js=False):
|
||||
"""点击后等待新tab出现并返回其对象
|
||||
:param by_js: 是否使用js点击,逻辑与click()一致
|
||||
:return: 新标签页对象,如果没有等到新标签页出现则抛出异常
|
||||
"""
|
||||
self.left(by_js=by_js)
|
||||
tid = self._ele.page._page.wait.new_tab()
|
||||
if not tid:
|
||||
raise RuntimeError('没有出现新标签页。')
|
||||
return self._ele.page._page.get_tab(tid)
|
||||
|
||||
def _click(self, client_x, client_y, button='left', count=1):
|
||||
"""实施点击
|
||||
:param client_x: 视口中的x坐标
|
||||
|
||||
@ -10,6 +10,7 @@ from typing import Union
|
||||
|
||||
from .downloader import DownloadMission
|
||||
from .._elements.chromium_element import ChromiumElement
|
||||
from .._pages.chromium_tab import WebPageTab, ChromiumTab
|
||||
|
||||
|
||||
class Clicker(object):
|
||||
@ -37,8 +38,11 @@ class Clicker(object):
|
||||
rename: str = None,
|
||||
suffix: str = None,
|
||||
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, list, tuple], by_js: bool = False) -> None: ...
|
||||
def to_upload(self, file_paths: Union[str, Path, list, tuple], by_js: bool = False) -> None: ...
|
||||
|
||||
def for_new_tab(self, by_js:bool=False)->Union[ChromiumTab, WebPageTab]:...
|
||||
|
||||
def _click(self, client_x: float, client_y: float, button: str = 'left', count: int = 1) -> None: ...
|
||||
|
||||
@ -130,6 +130,8 @@ class ChromiumBaseSetter(BasePageSetter):
|
||||
|
||||
if isinstance(files, str):
|
||||
files = files.split('\n')
|
||||
elif isinstance(files, Path):
|
||||
files = (files, )
|
||||
self._page._upload_list = [str(Path(i).absolute()) for i in files]
|
||||
|
||||
def headers(self, headers: dict) -> None:
|
||||
|
||||
@ -62,7 +62,7 @@ class ChromiumBaseSetter(BasePageSetter):
|
||||
|
||||
def auto_handle_alert(self, on_off: bool = True, accept: bool = True) -> None: ...
|
||||
|
||||
def upload_files(self, files: Union[str, list, tuple]) -> None: ...
|
||||
def upload_files(self, files: Union[str, Path, list, tuple]) -> None: ...
|
||||
|
||||
def blocked_urls(self, urls: Union[list, tuple, str, None]) -> None: ...
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user