Skip to content

Commit

Permalink
4.1.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
g1879 committed Dec 6, 2024
1 parent 3d9df53 commit ea7d539
Show file tree
Hide file tree
Showing 84 changed files with 308 additions and 301 deletions.
19 changes: 16 additions & 3 deletions DrissionPage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
允许任何人以个人身份使用或分发本项目源代码,但仅限于学习和合法非盈利目的。
个人或组织如未获得版权持有人授权,不得将本项目以源代码或二进制形式用于商业行为。
使用本项目需满足以下条款,如使用过程中出现违反任意一项条款的情形,授权自动失效。
* 禁止将DrissionPage应用到任何可能违反当地法律规定和道德约束的项目中
* 禁止将DrissionPage用于任何可能有损他人利益的项目中
* 禁止将DrissionPage用于攻击与骚扰行为
* 遵守Robots协议,禁止将DrissionPage用于采集法律或系统Robots协议不允许的数据
使用DrissionPage发生的一切行为均由使用人自行负责。
因使用DrissionPage进行任何行为所产生的一切纠纷及后果均与版权持有人无关,
版权持有人不承担任何使用DrissionPage带来的风险和损失。
版权持有人不对DrissionPage可能存在的缺陷导致的任何损失负任何责任。
"""
from ._base.chromium import Chromium
from ._configs.chromium_options import ChromiumOptions
Expand All @@ -12,4 +25,4 @@
from ._pages.session_page import SessionPage
from ._pages.web_page import WebPage

__version__ = '4.1.0.11'
__version__ = '4.1.0.13'
3 changes: 1 addition & 2 deletions DrissionPage/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from ._base.chromium import Chromium
from ._configs.chromium_options import ChromiumOptions
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from abc import abstractmethod
from copy import copy
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_base/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from abc import abstractmethod
from typing import Union, Tuple, List, Any, Optional, Dict
Expand Down
19 changes: 9 additions & 10 deletions DrissionPage/_base/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from pathlib import Path
from re import match
Expand Down Expand Up @@ -45,7 +44,7 @@ def __new__(cls, addr_or_opts=None, session_options=None):
if browser_id in cls._BROWSERS:
r = cls._BROWSERS[browser_id]
while not hasattr(r, '_driver'):
sleep(.1)
sleep(.05)
return r
r = object.__new__(cls)
r._chromium_options = opt
Expand Down Expand Up @@ -294,7 +293,7 @@ def quit(self, timeout=5, force=False, del_data=False):
rmtree(path, True)

def _new_tab(self, mix=True, url=None, new_window=False, background=False, new_context=False):
obj = MixTab if mix else ChromiumTab
tab_type = MixTab if mix else ChromiumTab
tab = None
if new_context:
tab = self._run_cdp('Target.createBrowserContext')['browserContextId']
Expand All @@ -308,20 +307,20 @@ def _new_tab(self, mix=True, url=None, new_window=False, background=False, new_c
kwargs['browserContextId'] = tab

if self.states.is_incognito:
return _new_tab_by_js(self, url, obj, new_window)
return _new_tab_by_js(self, url, tab_type, new_window)
else:
try:
tab = self._run_cdp('Target.createTarget', **kwargs)['targetId']
except CDPError:
return _new_tab_by_js(self, url, obj, new_window)
return _new_tab_by_js(self, url, tab_type, new_window)

while self.states.is_alive:
if tab in self._drivers:
break
sleep(.1)
sleep(.01)
else:
raise BrowserConnectError('浏览器已关闭')
tab = obj(self, tab)
tab = tab_type(self, tab)
if url:
tab.get(url)
return tab
Expand Down Expand Up @@ -484,8 +483,8 @@ def run_browser(chromium_options):
return is_headless, browser_id, is_exists


def _new_tab_by_js(browser: Chromium, url, obj, new_window):
mix = isinstance(obj, MixTab)
def _new_tab_by_js(browser: Chromium, url, tab_type, new_window):
mix = tab_type == MixTab
tab = browser._get_tab(mix=mix)
if url and not match(r'^.*?://.*', url):
raise ValueError(f'url也许需要加上http://?')
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_base/chromium.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from threading import Lock
from typing import List, Optional, Set, Dict, Union, Tuple, Literal, Any
Expand Down
5 changes: 2 additions & 3 deletions DrissionPage/_base/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from json import dumps, loads, JSONDecodeError
from queue import Queue, Empty
Expand Down Expand Up @@ -199,7 +198,7 @@ def start(self):
def stop(self):
self._stop()
while self._handle_event_th.is_alive() or self._recv_th.is_alive():
sleep(.1)
sleep(.01)
return True

def _stop(self):
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_base/driver.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from queue import Queue
from threading import Thread
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/chromium_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from pathlib import Path
from re import search
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/chromium_options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from pathlib import Path
from typing import Union, Any, Literal, Optional, Tuple
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/options_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from configparser import RawConfigParser, NoSectionError, NoOptionError
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/options_manage.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from configparser import RawConfigParser
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/session_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from copy import copy
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_configs/session_options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from http.cookiejar import CookieJar, Cookie
from pathlib import Path
Expand Down
25 changes: 15 additions & 10 deletions DrissionPage/_elements/chromium_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from json import loads
from os.path import basename
Expand Down Expand Up @@ -289,7 +288,7 @@ def offset(self, locator=None, x=None, y=None, timeout=None):

if ele and (loc_data is None or _check_ele(ele, loc_data)):
return ele
sleep(.1)
sleep(.01)

return NoneElement(page=self.owner, method='offset()',
args={'locator': locator, 'offset_x': x, 'offset_y': y, 'timeout': timeout})
Expand Down Expand Up @@ -451,7 +450,7 @@ def src(self, timeout=None, base64_to_bytes=True):
'&& this.naturalHeight > 0')
end_time = perf_counter() + timeout
while not self._run_js(js) and perf_counter() < end_time:
sleep(.1)
sleep(.05)

src = self.attr('href') if self.tag == 'link' else self.attr('src')
if not src:
Expand Down Expand Up @@ -488,7 +487,7 @@ def src(self, timeout=None, base64_to_bytes=True):
break
except CDPError:
pass
sleep(.1)
sleep(.05)

if not result:
return None
Expand Down Expand Up @@ -533,7 +532,7 @@ def get_screenshot(self, path=None, name=None, as_bytes=None, as_base64=None, sc
'&& typeof this.naturalHeight != "undefined" && this.naturalHeight > 0')
end_time = perf_counter() + self.timeout
while not self._run_js(js) and perf_counter() < end_time:
sleep(.1)
sleep(.05)
if scroll_to_center:
self.scroll.to_see(center=True)

Expand Down Expand Up @@ -905,7 +904,7 @@ def do_find():
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() <= end_time:
sleep(.1)
sleep(.01)
result = do_find()

if result:
Expand Down Expand Up @@ -1004,7 +1003,7 @@ def do_find():
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() < end_time:
sleep(.1)
sleep(.01)
result = do_find()

if result:
Expand Down Expand Up @@ -1043,7 +1042,7 @@ def do_find():
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() < end_time:
sleep(.1)
sleep(.01)
result = do_find()

if result:
Expand Down Expand Up @@ -1253,7 +1252,13 @@ def parse_js_result(page, ele, result, end_time):
r = page._run_cdp('Runtime.getProperties', objectId=result['objectId'], ownProperties=True)['result']
return [parse_js_result(page, ele, result=i['value'], end_time=end_time) for i in r if i['name'].isdigit()]

elif 'objectId' in result:
elif result.get('className') == 'Blob':
data = page._run_cdp('IO.read',
handle=f"blob:{page._run_cdp('IO.resolveBlob', objectId=result['objectId'])['uuid']}")[
'data']
return data

elif 'objectId' in result and result.get('className') == 'Blob':
timeout = end_time - perf_counter()
if timeout < 0:
return
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_elements/chromium_element.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from pathlib import Path
from typing import Union, Tuple, List, Any, Literal, Optional
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_elements/none_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from .._functions.settings import Settings
from ..errors import ElementNotFoundError
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_elements/none_element.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from typing import Any

Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_elements/session_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from html import unescape
from re import match, sub, DOTALL, search
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_elements/session_element.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from typing import Union, List, Tuple, Optional

Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_functions/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from json import load, dump, JSONDecodeError
from os import environ
Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_functions/browser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""
from typing import Union

Expand Down
3 changes: 1 addition & 2 deletions DrissionPage/_functions/by.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
@Copyright: (c) 2020 by g1879, Inc. All Rights Reserved.
"""


Expand Down
Loading

0 comments on commit ea7d539

Please sign in to comment.