0

I am scraping a site for for some details. I'm sending a POST request to an url and need to get the JSON response data for that because the data I need is not rendered into the HTML.

Normally I would just use axios.post() or an alternative but the rest api blocks requests without a session id so I have to use a headless browser.

So, is there a way to intercept the REST APIs JSON response, like you can check it in the 'Network' tab in developer tools?

porras
  • 61
  • 1
  • 7

1 Answers1

0

with axios, you have a middleware pipeline you can use to intercept a response from the server. This is in their readme under the section labeled "interceptors"

https://github.com/axios/axios#interceptors

// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });
FelizNaveedad
  • 358
  • 2
  • 7
  • I'm not using axios, becuase the rest api blocked my requests with HTTP forbidden with message 'session required'. So I needed to use a headless browser. – porras Aug 19 '19 at 00:08