Merge pull request !27 from g1879/debug
This commit is contained in:
g1879 2023-11-30 06:57:51 +00:00 committed by Gitee
commit 97e5bf0e12
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
21 changed files with 57 additions and 52 deletions

View File

@ -19,3 +19,5 @@ try:
from .configs.driver_options import DriverOptions
except ModuleNotFoundError:
pass
__version__ = '3.2.35'

View File

@ -387,7 +387,7 @@ class BasePage(BaseParser):
:param interval: 重试间隔
:return: 重试次数和间隔组成的tuple
"""
self._url = quote(url, safe='/:&?=%;#@+![]')
self._url = quote(url, safe='-_.~!*\'"();:@&=+$,/\\?#[]%')
retry = retry if retry is not None else self.retry_times
interval = interval if interval is not None else self.retry_interval
return retry, interval

View File

@ -200,7 +200,8 @@ class ChromiumDriver(object):
self._started = True
self.status = self._STARTED_
self._stopped.clear()
self._ws = create_connection(self._websocket_url, enable_multithread=True)
self._ws = create_connection(self._websocket_url, enable_multithread=True,
suppress_origin=True)
self._recv_th.start()
self._handle_event_th.start()
return True

View File

@ -1815,7 +1815,7 @@ class ChromiumSelect(object):
@property
def options(self):
"""返回所有选项元素组成的列表"""
return self._ele.eles('xpath://option')
return [e for e in self._ele.eles('xpath://option') if isinstance(e, ChromiumElement)]
@property
def selected_option(self):
@ -2020,7 +2020,7 @@ class ChromiumSelect(object):
def _dispatch_change(self):
"""触发修改动作"""
self._ele.run_js('this.dispatchEvent(new UIEvent("change"));')
self._ele.run_js('this.dispatchEvent(new Event("change", {bubbles: true}));')
class ChromiumElementWaiter(object):

View File

@ -131,7 +131,8 @@ class ChromiumPage(ChromiumBase):
def tabs(self):
"""返回所有标签页id组成的列表"""
j = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp
return [i['id'] for i in j if i['type'] == 'page']
return [i['id'] for i in j if i['type'] == 'page' and not i['url'].startswith('devtools://') and i[
'url'] != 'chrome://privacy-sandbox-dialog/notice']
@property
def main_tab(self):

View File

@ -3,18 +3,18 @@
@Author : g1879
@Contact : g1879@qq.com
"""
from json import load, dump
from json import load, dump, JSONDecodeError
from pathlib import Path
from platform import system
from subprocess import Popen, DEVNULL
from tempfile import gettempdir
from time import perf_counter, sleep
from platform import system
from requests import get as requests_get
from DrissionPage.configs.chromium_options import ChromiumOptions
from DrissionPage.errors import BrowserConnectError
from .tools import port_is_using
from ..configs.chromium_options import ChromiumOptions
from ..errors import BrowserConnectError
def connect_browser(option):
@ -43,7 +43,7 @@ def connect_browser(option):
# 传入的路径找不到主动在ini文件、注册表、系统变量中找
except FileNotFoundError:
from DrissionPage.easy_set import get_chrome_path
from ..easy_set import get_chrome_path
chrome_path = get_chrome_path(show_msg=False)
if not chrome_path:
@ -63,7 +63,6 @@ def get_launch_args(opt):
# ----------处理arguments-----------
result = set()
has_user_path = False
remote_allow = False
headless = False
for i in opt.arguments:
if i.startswith(('--load-extension=', '--remote-debugging-port=')):
@ -72,8 +71,6 @@ def get_launch_args(opt):
result.add(f'--user-data-dir={Path(i[16:]).absolute()}')
has_user_path = True
continue
elif i.startswith('--remote-allow-origins='):
remote_allow = True
elif i.startswith('--headless'):
headless = True
@ -85,9 +82,6 @@ def get_launch_args(opt):
path.mkdir(parents=True, exist_ok=True)
result.add(f'--user-data-dir={path}')
if not remote_allow:
result.add('--remote-allow-origins=*')
if not headless and system().lower() == 'linux':
from os import popen
r = popen('systemctl list-units | grep graphical.target')
@ -136,7 +130,10 @@ def set_prefs(opt):
f.write('{}')
with open(prefs_file, "r", encoding='utf-8') as f:
try:
prefs_dict = load(f)
except JSONDecodeError:
prefs_dict = {}
for pref in prefs:
value = prefs[pref]

View File

@ -1,7 +1,7 @@
from click import command, option
from DrissionPage import ChromiumPage
from DrissionPage.easy_set import set_paths, configs_to_here as ch
from ..chromium_page import ChromiumPage
from ..easy_set import set_paths, configs_to_here as ch
@command()

View File

@ -3,7 +3,7 @@
@Author : g1879
@Contact : g1879@qq.com
"""
from DrissionPage.errors import ElementNotFoundError
from ..errors import ElementNotFoundError
HANDLE_ALERT_METHOD = 'Page.handleJavaScriptDialog'
FRAME_ELEMENT = ('iframe', 'frame')

View File

@ -6,8 +6,8 @@
from pathlib import Path
from tempfile import gettempdir, TemporaryDirectory
from DrissionPage.commons.tools import port_is_using, clean_folder
from .options_manage import OptionsManager
from ..commons.tools import port_is_using, clean_folder
class ChromiumOptions(object):

View File

@ -4,7 +4,7 @@ download_path =
[chrome_options]
debugger_address = 127.0.0.1:9222
binary_location = chrome
arguments = ['--remote-allow-origins=*', '--no-first-run', '--disable-gpu', '--disable-infobars', '--disable-popup-blocking']
arguments = ['--no-first-run', '--disable-gpu', '--disable-infobars', '--disable-popup-blocking']
extensions = []
experimental_options = {'prefs': {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}}}
page_load_strategy = normal

View File

@ -8,8 +8,8 @@ from pathlib import Path
from requests import Session
from requests.structures import CaseInsensitiveDict
from DrissionPage.commons.web import cookies_to_tuple, set_session_cookies
from .options_manage import OptionsManager
from ..commons.web import cookies_to_tuple, set_session_cookies
class SessionOptions(object):

View File

@ -16,7 +16,7 @@ from .session_page import SessionPage
try:
from selenium import webdriver
from DrissionPage.mixpage.drission import Drission
from .mixpage.drission import Drission
from .configs.driver_options import DriverOptions
except ModuleNotFoundError:
pass

View File

@ -7,8 +7,8 @@ from abc import abstractmethod
from re import sub
from urllib.parse import quote
from DrissionPage.commons.web import format_html
from DrissionPage.commons.locator import get_loc
from ..commons.locator import get_loc
from ..commons.web import format_html
class BaseParser(object):

View File

@ -14,11 +14,11 @@ from selenium.webdriver.chrome.options import Options
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from tldextract import extract
from DrissionPage.commons.tools import get_pid_from_port, get_exe_from_port
from DrissionPage.commons.browser import connect_browser
from DrissionPage.commons.web import cookies_to_tuple
from DrissionPage.configs.session_options import SessionOptions, session_options_to_dict
from DrissionPage.configs.driver_options import DriverOptions
from ..commons.browser import connect_browser
from ..commons.tools import get_pid_from_port, get_exe_from_port
from ..commons.web import cookies_to_tuple
from ..configs.driver_options import DriverOptions
from ..configs.session_options import SessionOptions, session_options_to_dict
class Drission(object):
@ -399,7 +399,7 @@ def create_driver(chrome_path, driver_path, options):
# 若版本不对,获取对应 chromedriver 再试
except (WebDriverException, SessionNotCreatedException):
print('打开失败尝试获取driver。\n')
from DrissionPage.easy_set import get_match_driver, get_chrome_path
from ..easy_set import get_match_driver, get_chrome_path
if chrome_path == 'chrome':
chrome_path = get_chrome_path(show_msg=False, from_ini=False)

View File

@ -15,10 +15,10 @@ from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from .base import DrissionElement, BaseElement
from DrissionPage.commons.locator import str_to_loc, get_loc
from DrissionPage.commons.tools import get_usable_path
from DrissionPage.commons.web import format_html, get_ele_txt
from .session_element import make_session_ele
from ..commons.locator import str_to_loc, get_loc
from ..commons.tools import get_usable_path
from ..commons.web import format_html, get_ele_txt
class DriverElement(DrissionElement):

View File

@ -13,9 +13,9 @@ from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait
from .base import BasePage
from DrissionPage.commons.tools import get_usable_path
from .driver_element import DriverElement, make_driver_ele, Scroll, ElementWaiter
from .session_element import make_session_ele
from ..commons.tools import get_usable_path
class DriverPage(BasePage):

View File

@ -10,8 +10,8 @@ from lxml.etree import tostring
from lxml.html import HtmlElement, fromstring
from .base import DrissionElement, BasePage, BaseElement
from DrissionPage.commons.locator import get_loc
from DrissionPage.commons.web import get_ele_txt, make_absolute_link
from ..commons.locator import get_loc
from ..commons.web import get_ele_txt, make_absolute_link
class SessionElement(DrissionElement):

View File

@ -13,9 +13,9 @@ from requests.structures import CaseInsensitiveDict
from tldextract import extract
from .base import BasePage
from DrissionPage.configs.session_options import SessionOptions
from DrissionPage.commons.web import cookie_to_dict, set_session_cookies
from .session_element import SessionElement, make_session_ele
from ..commons.web import cookie_to_dict, set_session_cookies
from ..configs.session_options import SessionOptions
class SessionPage(BasePage):

View File

@ -9,9 +9,9 @@ from typing import Union
from selenium.webdriver.remote.webelement import WebElement
from .base import BaseElement
from DrissionPage.commons.locator import get_loc
from .driver_element import make_driver_ele
from .session_element import make_session_ele, SessionElement
from ..commons.locator import get_loc
class ShadowRootElement(BaseElement):

View File

@ -30,13 +30,23 @@ python 版本3.6 及以上
**📖 使用文档:** [点击查看](https://g1879.gitee.io/drissionpagedocs)
**交流 QQ 群:** 897838127[已满]、558778073
**交流 QQ 群:** 636361957
---
# 🔥 新版预告
# 🔥 新版尝鲜
查看下一步开发计划:[新版预告](https://g1879.gitee.io/drissionpagedocs/whatsnew/3_3/)
4.0 在 3.x 的基础上对底层进行了大幅重构,新增大量功能,改善运行效率和稳定性,优化项目结构,解决很多存在的问题。对比旧版本有质的提高。
现已发布 beta 版,欢迎尝鲜。
[4.0功能介绍](https://g1879.gitee.io/drissionpagedocs/whatsnew/4_0/)
安装目前是b14关注文档可能会有更新版本
```console
pip install DrissionPage==4.0.0b14
```
---
@ -110,15 +120,9 @@ python 版本3.6 及以上
---
# 🛠 使用文档
[点击跳转到使用文档](https://g1879.gitee.io/drissionpage)
---
# 🔖 版本历史
[点击查看版本历史](https://g1879.gitee.io/drissionpagedocs/history/3.x/)
[点击查看版本历史](https://g1879.gitee.io/drissionpagedocs/history/introduction/)
---

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="3.2.34",
version="3.2.35",
author="g1879",
author_email="g1879@qq.com",
description="Python based web automation tool. It can control the browser and send and receive data packets.",