{"id":27672,"date":"2024-11-24T15:09:13","date_gmt":"2024-11-24T07:09:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27672\/"},"modified":"2024-11-24T15:09:13","modified_gmt":"2024-11-24T07:09:13","slug":"node-js-%e8%af%b7%e6%b1%82%e7%bd%91%e9%a1%b5%e6%96%87%e6%9c%ac%e5%86%85%e5%ae%b9%e4%b9%b1%e7%a0%81%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27672\/","title":{"rendered":"Node.js \u8bf7\u6c42\u7f51\u9875\u6587\u672c\u5185\u5bb9\u4e71\u7801\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130391949295.jpg\" class=\"aligncenter\" title=\"Node.js \u8bf7\u6c42\u7f51\u9875\u6587\u672c\u5185\u5bb9\u4e71\u7801\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"Node.js \u8bf7\u6c42\u7f51\u9875\u6587\u672c\u5185\u5bb9\u4e71\u7801\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>node\u4f7f\u7528request\u83b7\u53d6html\u6587\u672c\u5185\u5bb9\u7f16\u7801\u5f02\u5e38<\/strong><\/p>\n<p>\u5728node\u73af\u5883\u4e2d\uff0c\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\u95ee\u9898\u3002<\/p>\n<p>\u5177\u4f53\u8868\u73b0\u4e3a\uff1a\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u6b63\u5e38\u7684\u6587\u672c\uff0c\u800c\u5728node\u4e2d\u6253\u5370\u51fa\u7684\u5374\u662f\u4e71\u7801\uff0c\u5982\u5927\u91cf\u201c\ufffd\u201d\u5b57\u7b26\u3002<\/p>\n<p>\u4ea7\u751f\u6b64\u95ee\u9898\u7684\u539f\u56e0\u662f\uff1a<\/p>\n<ul>\n<li> <strong>\u7f16\u7801\u4e0d\u4e00\u81f4\uff1a<\/strong>\u7f51\u9875\u8fd4\u56de\u7684body\u5185\u5bb9\u53ef\u80fd\u662f\u4ee5\u4e00\u79cd\u6d4f\u89c8\u5668\u65e0\u6cd5\u76f4\u63a5\u8bc6\u522b\u7684\u7f16\u7801\u683c\u5f0f\uff0c\u5982GBK\uff0c\u5bfc\u81f4node\u6253\u5370\u4e71\u7801\u3002<\/li>\n<li> <strong>\u7f3a\u5c11\u5b57\u7b26\u96c6\u4fe1\u606f\uff1a<\/strong>HTTP\u54cd\u5e94\u5934\u4e2d\u53ef\u80fd\u7f3a\u5c11\u5b57\u7b26\u96c6\u4fe1\u606f\uff0c\u5bfc\u81f4node\u65e0\u6cd5\u81ea\u52a8\u8bc6\u522b\u7f16\u7801\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li> <strong>\u4f7f\u7528\u5408\u9002\u7684\u7f16\u7801\u5e93\uff1a<\/strong>\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u652f\u6301\u66f4\u591a\u7f16\u7801\u683c\u5f0f\u7684\u5e93\uff0c\u5982axios\u3002axios\u4f1a\u81ea\u52a8\u8bc6\u522b\u5e76\u89e3\u7801\u54cd\u5e94\u5185\u5bb9\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre>const axios = require('axios')\n\nfunction getGoods () {\n    axios('https:\/\/www.58moto.com\/used-car\/1470264')\n    .then(res =&gt; {\n        console.log(res.data)\n    })\n}\n\ngetGoods()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u4f7f\u7528axios\uff0c\u65e0\u9700\u624b\u52a8\u6307\u5b9a\u7f16\u7801\u683c\u5f0f\uff0c\u5373\u53ef\u83b7\u5f97\u6b63\u786e\u7684\u89e3\u7801\u5185\u5bb9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNode.js \u8bf7\u6c42\u7f51\u9875\u6587\u672c\u5185\u5bb9\u4e71\u7801\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>node\u4f7f\u7528request\u83b7\u53d6html\u6587\u672c\u5185\u5bb9\u7f16\u7801\u5f02\u5e38 \u5728node\u73af\u5883\u4e2d\uff0c\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\u95ee\u9898\u3002 \u5177\u4f53\u8868\u73b0\u4e3a\uff1a\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u6b63\u5e38\u7684\u6587\u672c\uff0c\u800c\u5728node\u4e2d\u6253\u5370\u51fa\u7684\u5374\u662f\u4e71\u7801\uff0c\u5982\u5927\u91cf\u201c\ufffd\u201d\u5b57\u7b26\u3002 \u4ea7\u751f\u6b64\u95ee\u9898\u7684\u539f\u56e0\u662f\uff1a \u7f16\u7801\u4e0d\u4e00\u81f4\uff1a\u7f51\u9875\u8fd4\u56de\u7684body\u5185\u5bb9\u53ef\u80fd\u662f\u4ee5\u4e00\u79cd\u6d4f\u89c8\u5668\u65e0\u6cd5\u76f4\u63a5\u8bc6\u522b\u7684\u7f16\u7801\u683c\u5f0f\uff0c\u5982GBK\uff0c\u5bfc\u81f4node\u6253\u5370\u4e71\u7801\u3002 \u7f3a\u5c11\u5b57\u7b26\u96c6\u4fe1\u606f\uff1aHTTP\u54cd\u5e94\u5934\u4e2d\u53ef\u80fd\u7f3a\u5c11\u5b57\u7b26\u96c6\u4fe1\u606f\uff0c\u5bfc\u81f4node\u65e0\u6cd5\u81ea\u52a8\u8bc6\u522b\u7f16\u7801\u683c\u5f0f\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u4f7f\u7528\u5408\u9002\u7684\u7f16\u7801\u5e93\uff1a\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u652f\u6301\u66f4\u591a\u7f16\u7801\u683c\u5f0f\u7684\u5e93\uff0c\u5982axios\u3002axios\u4f1a\u81ea\u52a8\u8bc6\u522b\u5e76\u89e3\u7801\u54cd\u5e94\u5185\u5bb9\u3002\u4ee3\u7801\u5982\u4e0b\uff1a const axios = require(&#8216;axios&#8217;) function getGoods () { axios(&#8216;https:\/\/www.58moto.com\/used-car\/1470264&#8217;) .then(res =&gt; { console.log(res.data) }) } getGoods() \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u4f7f\u7528axios\uff0c\u65e0\u9700\u624b\u52a8\u6307\u5b9a\u7f16\u7801\u683c\u5f0f\uff0c\u5373\u53ef\u83b7\u5f97\u6b63\u786e\u7684\u89e3\u7801\u5185\u5bb9\u3002 \u4ee5\u4e0a\u5c31\u662fNode.js \u8bf7\u6c42\u7f51\u9875\u6587\u672c\u5185\u5bb9\u4e71\u7801\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27672","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27672"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27672\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}