改进创建ResponseData逻辑

This commit is contained in:
g1879 2023-04-05 22:42:01 +08:00
parent 322ee10bd0
commit 57b46e7b26
3 changed files with 10 additions and 6 deletions

View File

@ -1204,16 +1204,20 @@ class NetworkListener(object):
request_id = kwargs['requestId'] request_id = kwargs['requestId']
if request_id in self._requests: if request_id in self._requests:
try: try:
body = self._page.run_cdp('Network.getResponseBody', requestId=request_id)['body'] r = self._page.run_cdp('Network.getResponseBody', requestId=request_id)
except: body = r['body']
body = None is_base64 = r['base64Encoded']
except CallMethodError:
body = ''
is_base64 = False
request = self._requests[request_id] request = self._requests[request_id]
target = request['target'] target = request['target']
rd = ResponseData(request_id, request['response'], rd = ResponseData(request_id, request['response'],
body, self._page.tab_id, target) body, self._page.tab_id, target)
rd.postData = request['post_data'] rd.postData = request['post_data']
rd._requestHeaders = request['request_headers'] rd._base64_body = is_base64
rd.requestHeaders = request['request_headers']
self._results[target] = rd self._results[target] = rd
def _requestWillBeSent(self, **kwargs): def _requestWillBeSent(self, **kwargs):

View File

@ -2,7 +2,7 @@ requests
lxml lxml
cssselect cssselect
DownloadKit>=0.5.3 DownloadKit>=0.5.3
FlowViewer>=0.2.10 FlowViewer>=0.3.0
websocket-client websocket-client
click click
tldextract tldextract

View File

@ -23,7 +23,7 @@ setup(
'requests', 'requests',
'cssselect', 'cssselect',
'DownloadKit>=0.5.3', 'DownloadKit>=0.5.3',
'FlowViewer>=0.2.10', 'FlowViewer>=0.3.0',
'websocket-client', 'websocket-client',
'click~=8.1.3', 'click~=8.1.3',
'tldextract' 'tldextract'