nightmare js: get json response from POST request

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:57:06

问题


I am using nightmare to login to a page and click a few links. Then I go to a specific url for which a POST request is made. I want to retrieve the json response from the POST request. So far, I have this

var Nightmare = require('nightmare');
const nightmare = Nightmare({ show: true });
nightmare
    .goto('https://my.url/')
    .type('#user_id', 'myUserId')
    .type('#password', 'passw0rd')
    .click('#button-login')
    .wait(3000)
    .goto('specific-url') // this URL loads a page with some data
    .end()
    .then(console.log)    // this prints stuff like HTTP response: OK
    .catch((error) => {
    console.error('Search failed:', error);
});

When I go to the specific-url, a POST request is made and the page is populated with data. I can see the page load properly but I want the data in Json format because I don't wanna parse the page.

Any ideas on how to retrieve the response json?

来源:https://stackoverflow.com/questions/46222072/nightmare-js-get-json-response-from-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!