Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to get the body of the xhr request #87

Open
dima23113 opened this issue Mar 1, 2025 · 0 comments
Open

Error when trying to get the body of the xhr request #87

dima23113 opened this issue Mar 1, 2025 · 0 comments

Comments

@dima23113
Copy link

Hi! Why do I get an error if ResponseReceived works, I get the real request id and it has a status code 200?

Error getting body No resource with given identifier found
command:Network.getResponseBody
params:{'requestId': RequestId('3980.82')} [code: -32000]

`
  class RequestMonitor:
    def __init__(self):
        # Храним пары [URL, request_id]
        self.requests: list[list[str | cdp.network.RequestId]] = []
        self.last_request: float | None = None
        self.lock = asyncio.Lock()

    async def listen(self, page: uc.Tab):
        async def handler(evt: cdp.network.ResponseReceived):
            async with self.lock:
                # Отслеживаем только XHR-ответы с ненулевым размером данных
                if "goldapple.ru/front/api/catalog/products" in evt.response.url:
                    self.requests.append([evt.response.url, evt.request_id])
                    print(evt.request_id.to_json())
                    self.last_request = time.time()


        page.add_handler(cdp.network.ResponseReceived, handler)

    async def receive(self, page: uc.Tab):
        responses: list[ResponseType] = []

        print("Реквесты: ", self.requests)
        for request in self.requests:
            try:
                if not isinstance(request[1], cdp.network.RequestId):
                    raise ValueError('Request ID is not of type RequestId')
                res = await page.send(cdp.network.get_response_body(request[1]))
                if res is None:
                    continue
                responses.append({
                    'url': request[0],
                    'body': res[0],
                    'is_base64': res[1]
                })
            except Exception as e:
                print('Error getting body', e)
        return responses
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant