Correctly get page content after JS Execution

- Thanks for @AbdullahY36 for the heads-up.

**Update reference** https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event
This commit is contained in:
Karim shoair
2024-11-10 16:11:46 +02:00
parent 43045e3eb2
commit 239e2c73bf
3 changed files with 13 additions and 7 deletions
+7 -3
View File
@@ -28,10 +28,14 @@ class Response:
def adaptor(self) -> Union[Adaptor, None]:
"""Generate Adaptor instance from this response if possible, otherwise return None"""
automatch_domain = self.adaptor_arguments.pop('automatch_domain', None)
if self.content:
return Adaptor(body=self.content, url=automatch_domain or self.url, encoding=self.encoding, **self.adaptor_arguments)
elif self.text:
if self.text:
# For playwright that will be the response after all JS executed
return Adaptor(text=self.text, url=automatch_domain or self.url, encoding=self.encoding, **self.adaptor_arguments)
elif self.content:
# For playwright, that's after all JS is loaded but not all of them executed, because playwright doesn't offer something like page.content()
# To get response Bytes after the load states
# Reference: https://playwright.dev/python/docs/api/class-page
return Adaptor(body=self.content, url=automatch_domain or self.url, encoding=self.encoding, **self.adaptor_arguments)
return None
def __repr__(self):