diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 4c7aee0..1d814cb 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -84,8 +84,9 @@ class Browser(object): @property def tabs(self): """返回所有标签页id组成的列表""" - j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp - return [i['id'] for i in j if i['type'] == 'page'] + # j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp + j = self.run_cdp('Target.getTargets')['targetInfos'] + return [i['targetId'] for i in j if i['type'] == 'page'] @property def process_id(self): diff --git a/DrissionPage/_base/chromium_driver.pyi b/DrissionPage/_base/chromium_driver.pyi index 378879b..fac8ab5 100644 --- a/DrissionPage/_base/chromium_driver.pyi +++ b/DrissionPage/_base/chromium_driver.pyi @@ -7,6 +7,7 @@ from queue import Queue from threading import Thread, Event from typing import Union, Callable, Dict, Optional +from requests import Response from websocket import WebSocket @@ -57,3 +58,5 @@ class ChromiumDriver(object): class BrowserDriver(ChromiumDriver): BROWSERS: Dict[str, ChromiumDriver] = ... + + def get(self, url) -> Response: ... diff --git a/DrissionPage/_commons/web.py b/DrissionPage/_commons/web.py index 5a438f3..543d222 100644 --- a/DrissionPage/_commons/web.py +++ b/DrissionPage/_commons/web.py @@ -54,7 +54,7 @@ def get_ele_txt(e): if sub('[ \n\t\r]', '', el) != '': # 字符除了回车和空格还有其它内容 txt = el if not pre: - txt = txt.replace('\n', ' ').strip(' ') + txt = txt.replace('\r\n', ' ').replace('\n', ' ').strip(' ') txt = sub(r' {2,}', ' ', txt) str_list.append(txt) diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index 467ae1c..2017eee 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -264,6 +264,7 @@ class ChromiumPage(ChromiumBase): for tab in tabs: self.browser.close_tab(tab) + sleep(.2) while len(self.tabs) != end_len: sleep(.1) diff --git a/DrissionPage/_units/network_listener.py b/DrissionPage/_units/network_listener.py index cd87112..9732330 100644 --- a/DrissionPage/_units/network_listener.py +++ b/DrissionPage/_units/network_listener.py @@ -203,7 +203,7 @@ class NetworkListener(object): if ((self._is_regex and search(target, kwargs['request']['url'])) or (not self._is_regex and target in kwargs['request']['url'])) and ( not self._method or kwargs['request']['method'] in self._method): - p = self._request_ids.setdefault(rid, DataPacket(self._page.tab_id, None)) + p = self._request_ids.setdefault(rid, DataPacket(self._page.tab_id, target)) p._raw_request = kwargs if kwargs['request'].get('hasPostData', None) and not kwargs['request'].get('postData', None): p._raw_post_data = self._driver.call_method('Network.getRequestPostData', requestId=rid)['postData'] @@ -220,7 +220,9 @@ class NetworkListener(object): request._resource_type = kwargs['type'] def _responseReceivedExtraInfo(self, **kwargs): - self._extra_info_ids[kwargs['requestId']]['response'] = kwargs + r = self._extra_info_ids.get(kwargs['requestId']) + if r: + r['response'] = kwargs def _loading_finished(self, **kwargs): """请求完成时处理方法""" diff --git a/setup.py b/setup.py index 24c2142..780d1d4 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="4.0.0b4", + version="4.0.0b5", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.",