4.0.0b5修复几个隐藏问题

This commit is contained in:
g1879 2023-10-31 19:57:37 +08:00
parent b8382e3e5f
commit 5f0ef46b93
6 changed files with 13 additions and 6 deletions

View File

@ -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):

View File

@ -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: ...

View File

@ -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)

View File

@ -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)

View File

@ -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):
"""请求完成时处理方法"""

View File

@ -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.",