Fixing the way Response object handles sub items in some edge cases
+ Do it with the least impact on performance
This commit is contained in:
@@ -114,14 +114,14 @@ class CamoufoxEngine:
|
||||
response = Response(
|
||||
url=res.url,
|
||||
text=page.content(),
|
||||
content=res.body(),
|
||||
body=res.body(),
|
||||
status=res.status,
|
||||
reason=res.status_text,
|
||||
encoding=encoding,
|
||||
cookies={cookie['name']: cookie['value'] for cookie in page.context.cookies()},
|
||||
headers=res.all_headers(),
|
||||
request_headers=res.request.all_headers(),
|
||||
adaptor_arguments=self.adaptor_arguments
|
||||
**self.adaptor_arguments
|
||||
)
|
||||
page.close()
|
||||
|
||||
|
||||
@@ -224,14 +224,14 @@ class PlaywrightEngine:
|
||||
response = Response(
|
||||
url=res.url,
|
||||
text=page.content(),
|
||||
content=res.body(),
|
||||
body=res.body(),
|
||||
status=res.status,
|
||||
reason=res.status_text,
|
||||
encoding=encoding,
|
||||
cookies={cookie['name']: cookie['value'] for cookie in page.context.cookies()},
|
||||
headers=res.all_headers(),
|
||||
request_headers=res.request.all_headers(),
|
||||
adaptor_arguments=self.adaptor_arguments
|
||||
**self.adaptor_arguments
|
||||
)
|
||||
page.close()
|
||||
return response
|
||||
|
||||
@@ -53,14 +53,14 @@ class StaticEngine:
|
||||
return Response(
|
||||
url=str(response.url),
|
||||
text=response.text,
|
||||
content=response.content,
|
||||
body=response.content,
|
||||
status=response.status_code,
|
||||
reason=response.reason_phrase,
|
||||
encoding=response.encoding or 'utf-8',
|
||||
cookies=dict(response.cookies),
|
||||
headers=dict(response.headers),
|
||||
request_headers=dict(response.request.headers),
|
||||
adaptor_arguments=self.adaptor_arguments
|
||||
**self.adaptor_arguments
|
||||
)
|
||||
|
||||
def get(self, url: str, stealthy_headers: Optional[bool] = True, **kwargs: Dict) -> Response:
|
||||
|
||||
@@ -12,15 +12,14 @@ from scrapling.core._types import Any, List, Type, Union, Optional, Dict, Callab
|
||||
class Response(Adaptor):
|
||||
"""This class is returned by all engines as a way to unify response type between different libraries."""
|
||||
|
||||
def __init__(self, url: str, text: str, content: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict, adaptor_arguments: Dict, encoding: str = 'utf-8'):
|
||||
def __init__(self, url: str, text: str, body: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict, encoding: str = 'utf-8', **adaptor_arguments: Dict):
|
||||
automatch_domain = adaptor_arguments.pop('automatch_domain', None)
|
||||
super().__init__(text=text, body=content, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
||||
|
||||
self.status = status
|
||||
self.reason = reason
|
||||
self.cookies = cookies
|
||||
self.headers = headers
|
||||
self.request_headers = request_headers
|
||||
super().__init__(text=text, body=body, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
||||
# For back-ward compatibility
|
||||
self.adaptor = self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user