Calculate status text manually if it's not returned by PlayWright API
This commit is contained in:
@@ -4,6 +4,7 @@ from scrapling.core._types import Union, Callable, Optional, Dict, List, Literal
|
||||
from scrapling.engines.toolbelt import (
|
||||
Response,
|
||||
do_nothing,
|
||||
StatusText,
|
||||
get_os_name,
|
||||
intercept_route,
|
||||
check_type_validity,
|
||||
@@ -111,12 +112,17 @@ class CamoufoxEngine:
|
||||
if 'charset=' in content_type.lower():
|
||||
encoding = content_type.lower().split('charset=')[-1].split(';')[0].strip()
|
||||
|
||||
status_text = res.status_text
|
||||
# PlayWright API sometimes give empty status text for some reason!
|
||||
if not status_text:
|
||||
status_text = StatusText.get(res.status)
|
||||
|
||||
response = Response(
|
||||
url=res.url,
|
||||
text=page.content(),
|
||||
body=page.content().encode('utf-8'),
|
||||
status=res.status,
|
||||
reason=res.status_text,
|
||||
reason=status_text,
|
||||
encoding=encoding,
|
||||
cookies={cookie['name']: cookie['value'] for cookie in page.context.cookies()},
|
||||
headers=res.all_headers(),
|
||||
|
||||
Reference in New Issue
Block a user