Closed hoodoos closed 7 years ago
Same issue, anyone could help?
It's because the communication between Horseman and PhantomJS is asynchronous. When your .on
callback get called in NodeJs the PhantomJS callback has already run and the body is gone.
You can use .at
to register a callback that runs in PhantomJS instead of NodeJS and it will have access to the response.
It seems like that the issue is associated with PhantomJS itself, the response body from PhantomJS is empty. I've also tried .at
and the result is same:
node-phantom-simple:debug Response...
node-phantom-simple:debug +14ms
node-phantom-simple:debug body: {"contentType":"application/javascript","headers":[{"name":"Server","value":"Tengine"},{"name":"Content-Type","value":"application/javascript"},{"name":"Connection","value":"keep-alive"},{"name":"Date","value":"Thu, 14 Dec 2017 03:56:46 GMT"},{"name":"Vary","value":"Accept-Encoding"},{"name":"x-oss-request-id","value":"5A31F67EF83B265808446569"},{"name":"x-oss-object-type","value":"Normal"},{"name":"x-oss-storage-class","value":"Standard"},{"name":"Content-MD5","value":"kAoAVXbzIgek/4Tykq+lew=="},{"name":"x-oss-server-time","value":"0"},{"name":"Cache-Control","value":"max-age=2592000,s-maxage=3600"},{"name":"Access-Control-Allow-Origin","value":"*"},{"name":"X-Source-Scheme","value":"https"},{"name":"Content-Encoding","value":"gzip"},{"name":"Via","value":"cache23.l2cm12-1[0,200-0,H], cache48.l2cm12-1[0,0], cache10.cn298[0,200-0,H], cache7.cn298[1,0]"},{"name":"Age","value":"1748"},{"name":"X-Cache","value":"HIT TCP_MEM_HIT dirn:4:680392651 mlen:-1"},{"name":"X-Swift-SaveTime","value":"Thu, 14 Dec 2017 03:59:00 GMT"},{"name":"X-Swift-CacheTime","value":"3466"},{"name":"Timing-Allow-Origin","value":"*"},{"name":"EagleId","value":"8ccd84cf15132255541833781e"}],"id":5,"redirectURL":null,"stage":"end","status":200,"statusText":"OK","time":"2017-12-14T04:25:54.277Z","url":"https://g.alicdn.com/??kissy/k/6.2.4/seed-min.js,kg/global-util/1.0.5/index-min.js,tb/tracker/4.2.1/p/index/index.js,kg/tb-nav/2.5.3/index-min.js,secdev/sufei_data/3.0.8/index.js"}
node-phantom-simple:debug +0ms
node-phantom-simple:debug Response...
node-phantom-simple:debug +29ms
node-phantom-simple:debug body: {"body":"","bodySize":31434,"contentType":"application/javascript","headers":[{"name":"Server","value":"Tengine"},{"name":"Content-Type","value":"application/javascript"},{"name":"Connection","value":"keep-alive"},{"name":"Date","value":"Tue, 05 Dec 2017 15:11:00 GMT"},{"name":"Vary","value":"Accept-Encoding"},{"name":"x-oss-request-id","value":"5A26B7048EAA1FFE3B28BF2B"},{"name":"x-oss-object-type","value":"Normal"},{"name":"x-oss-hash-crc64ecma","value":"12573705527815366226"},{"name":"x-oss-storage-class","value":"Standard"},{"name":"Cache-Control","value":"max-age=31104000,s-maxage=31104000"},{"name":"Content-MD5","value":"iZM2GxVvIfJ+6HmET4NF/g=="},{"name":"x-oss-server-time","value":"2"},{"name":"Access-Control-Allow-Origin","value":"*"},{"name":"X-Source-Scheme","value":"https"},{"name":"Content-Encoding","value":"gzip"},{"name":"Via","value":"cache9.l2cm12-1[0,200-0,H], cache47.l2cm12-1[0,0], cache7.cn298[0,200-0,H], cache2.cn298[0,0]"},{"name":"Age","value":"738894"},{"name":"X-Cache","value":"HIT TCP_MEM_HIT dirn:8:198388762 mlen:-1"},{"name":"X-Swift-SaveTime","value":"Tue, 05 Dec 2017 15:11:56 GMT"},{"name":"X-Swift-CacheTime","value":"31103944"},{"name":"Timing-Allow-Origin","value":"*"},{"name":"EagleId","value":"8ccd84ca15132255542614602e"}],"id":12,"redirectURL":null,"stage":"start","status":200,"statusText":"OK","time":"2017-12-14T04:25:54.307Z","url":"https://g.alicdn.com/alilog/??s/7.6.27/plugin/aplus_client.js,aplus_cplugin/0.2.8/toolkit.js,aplus_cplugin/0.2.8/monitor.js,s/7.6.27/aplus_std.js,aplus_cplugin/0.2.8/aol.js,s/7.6.27/plugin/aplus_spmact.js?v=20171205231003"}
node-phantom-simple:debug +1ms
node-phantom-simple:debug Response...
node-phantom-simple:debug +0ms
node-phantom-simple:debug body: {"contentType":"application/javascript","headers":[{"name":"Server","value":"Tengine"},{"name":"Content-Type","value":"application/javascript"},{"name":"Connection","value":"keep-alive"},{"name":"Date","value":"Thu, 14 Dec 2017 03:59:58 GMT"},{"name":"Vary","value":"Accept-Encoding"},{"name":"x-oss-request-id","value":"5A31F73E991D4F5C77580216"},{"name":"x-oss-object-type","value":"Normal"},{"name":"x-oss-hash-crc64ecma","value":"2350743250595008233"},{"name":"x-oss-storage-class","value":"Standard"},{"name":"Content-MD5","value":"1HFosVNjnw+LtF9sny52ew=="},{"name":"x-oss-server-time","value":"1"},{"name":"Cache-Control","value":"max-age=2592000,s-maxage=3600"},{"name":"Access-Control-Allow-Origin","value":"*"},{"name":"X-Source-Scheme","value":"https"},{"name":"Content-Encoding","value":"gzip"},{"name":"Via","value":"cache28.l2cm12-1[0,200-0,H], cache46.l2cm12-1[0,0], cache9.cn298[0,200-0,H], cache4.cn298[0,0]"},{"name":"Age","value":"1556"},{"name":"X-Cache","value":"HIT TCP_MEM_HIT dirn:8:605410339 mlen:-1"},{"name":"X-Swift-SaveTime","value":"Thu, 14 Dec 2017 04:00:03 GMT"},{"name":"X-Swift-CacheTime","value":"3595"},{"name":"Timing-Allow-Origin","value":"*"},{"name":"EagleId","value":"8ccd84cc15132255542021653e"}],"id":7,"redirectURL":null,"stage":"end","status":200,"statusText":"OK","time":"2017-12-14T04:25:54.308Z","url":"https://g.alicdn.com/??kg/route-map-http/0.0.3/index.js,kg/home-2017/1.1.3/index.js,kg/pattern/2.1.3/index-min.js,kg/pattern/2.1.3/lib/image-min.js,kg/pattern/2.1.3/lib/reporter-min.js,kg/pattern/2.1.3/lib/io-min.js,kg/home-2017/1.1.3/c/fixedtool/index.css.js,kg/pattern/2.1.3/lib/event-min.js"}
I try to get a body of XHR call using .on('resourceReceived', function(response){ ... }), but response.body is always empty or null. Is there anyway to overcome it?