简体   繁体   English

无法在Dictionary Node.js中实现目标值

[英]Cant target value in Dictionary Node.js

const j = require('request').jar();
const request = require('request').defaults({
  jar: j
});

request({
  method: 'GET',
  url: "https://www.google.com/gen_204?atyp=csi&ei=_-34WouCCoaWsgWUsLfoBQ&s=newtab&adh=&conn=onchange&ima=1&ime=0&imeb=0&imeo=0&mem=ujhs.10,tjhs.10,jhsl.2190&rt=aft.13,ol.20,prt.14,xjs.317,xjsee.317,xjses.230,xjsls.37,wsrt.95,cst.0,dnst.0,rqst.18,rspt.10,rqstt.27,unt.25,cstt.25,dit.111&zx=1526264059738"
}, function(err, res, body) {
  console.log(JSON.stringify(j._jar.cookies));

this gives: 这给出了:

undefined 未定义

  console.log(JSON.stringify(j));

this gives: 这给出了:

{"_jar":{"version":"tough-cookie@2.3.3","storeType":"MemoryCookieStore","rejectPublicSuffixes":true,"cookies":[{"key":"NID","value":"130=F2nMvgnjWwGNndAE7c0rlU8AIgvX-EsDL-qc_kFLT18upWh87niN-_Th5oMbUyDe7LV5HWNVcsUKb6SUwQuC6VTWgC-jnPmHo4tLnFPb8r7p3CEbMN7MYxAFpucRfl8o","expires":"2018-11-13T03:50:35.000Z","domain":"google.com","path":"/","httpOnly":true,"hostOnly":false,"creation":"2018-05-14T03:50:35.944Z","lastAccessed":"2018-05-14T03:50:35.944Z"}]}} {“ _jar”:{“ version”:“ tough-cookie@2.3.3”,“ storeType”:“ MemoryCookieStore”,“ rejectPublicSuffixes”:true,“ cookies”:[{“ key”:“ NID”,“ value “:” 130 = F2nMvgnjWwGNndAE7c0rlU8AIgvX-EsDL-qc_kFLT18upWh87niN-_Th5oMbUyDe7LV5HWNVcsUKb6SUwQuC6VTWgC-jnPmHo4tLnFPb8r7p3CEbMYR“:”“:”“:”“:” ,“ httpOnly”:true,“ hostOnly”:false,“创建”:“ 2018-05-14T03:50:35.944Z”,“ lastAccessed”:“” 2018-05-14T03:50:35.944Z“}}}}

});

I need the cookies:[] as shown in the output above. 我需要cookies:[],如上面的输出所示。

j is an instance of RequestJar Object while j._jar is an instance of CookieJar Object. jRequestJar对象的实例,而j._jarCookieJar对象的实例。 CookieJar(_jar) does not have cookies field but you can access JSON.parse(JSON.stringify(j._jar)).cookies CookieJar(_jar)没有cookies字段,但是您可以访问JSON.parse(JSON.stringify(j._jar)).cookies

request({
  method: 'GET',
  url: "https://www.google.com/gen_204?atyp=csi&ei=_-34WouCCoaWsgWUsLfoBQ&s=newtab&adh=&conn=onchange&ima=1&ime=0&imeb=0&imeo=0&mem=ujhs.10,tjhs.10,jhsl.2190&rt=aft.13,ol.20,prt.14,xjs.317,xjsee.317,xjses.230,xjsls.37,wsrt.95,cst.0,dnst.0,rqst.18,rspt.10,rqstt.27,unt.25,cstt.25,dit.111&zx=1526264059738"
}, function(err, res, body) {
    console.log(JSON.parse(JSON.stringify(j._jar)).cookies);
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM