{"id":27527,"date":"2024-11-24T17:32:58","date_gmt":"2024-11-24T09:32:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27527\/"},"modified":"2024-11-24T17:32:58","modified_gmt":"2024-11-24T09:32:58","slug":"node-js%e7%88%ac%e5%8f%96%e7%bd%91%e9%a1%b5%e7%bc%96%e7%a0%81%e5%bc%82%e5%b8%b8%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27527\/","title":{"rendered":"Node.js\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173128573256405.jpg\" class=\"aligncenter\" title=\"Node.js\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Node.js\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>node\u4e2d\u89e3\u51b3\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5728node\u73af\u5883\u4e2d\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\uff0c\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\uff0c\u5bfc\u81f4\u6253\u5370\u7684\u7ed3\u679c\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>const request = require('request');\n\nfunction getGoods() {\n    request('https:\/\/www.58moto.com\/used-car\/1470264', (err, res, body) =&gt; {\n        console.log(body)\n    })\n}\n\ngetGoods()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6d4f\u89c8\u5668\u4e2d\u7684\u54cd\u5e94\u662f\u6b63\u5e38\u7684\uff0c\u800c\u5b9e\u9645\u6253\u5370\u7684\u7ed3\u679c\u5374\u662f\u4e00\u4e32\u4e71\u7801\uff0c\u8fd9\u662f\u7531\u4e8e\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\u9020\u6210\u7684\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528axios\u5e93\u6765\u8fdb\u884c\u722c\u53d6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>const axios = require('axios');\n\nasync function getGoods() {\n    const res = await axios.get('https:\/\/www.58moto.com\/used-car\/1470264');\n    const html = res.data;\n    console.log(html);\n}\n\ngetGoods();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528axios\u722c\u53d6\u7f51\u9875\u65f6\uff0c\u8fd4\u56de\u7684body\u5df2\u7ecf\u7ecf\u8fc7\u4e86\u89e3\u7801\u5904\u7406\uff0c\u56e0\u6b64\u6253\u5370\u7684\u7ed3\u679c\u53ef\u4ee5\u6b63\u5e38\u663e\u793a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNode.js\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\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\u4e2d\u89e3\u51b3\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u7684\u95ee\u9898 \u5728node\u73af\u5883\u4e2d\u4f7f\u7528request\u722c\u53d6\u7f51\u9875\uff0c\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\uff0c\u5bfc\u81f4\u6253\u5370\u7684\u7ed3\u679c\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\u3002\u4ee3\u7801\u5982\u4e0b\uff1a const request = require(&#8216;request&#8217;); function getGoods() { request(&#8216;https:\/\/www.58moto.com\/used-car\/1470264&#8217;, (err, res, body) =&gt; { console.log(body) }) } getGoods() \u767b\u5f55\u540e\u590d\u5236 \u6d4f\u89c8\u5668\u4e2d\u7684\u54cd\u5e94\u662f\u6b63\u5e38\u7684\uff0c\u800c\u5b9e\u9645\u6253\u5370\u7684\u7ed3\u679c\u5374\u662f\u4e00\u4e32\u4e71\u7801\uff0c\u8fd9\u662f\u7531\u4e8e\u54cd\u5e94\u7684body\u7f16\u7801\u5f02\u5e38\u9020\u6210\u7684\u3002 \u89e3\u51b3\u65b9\u6cd5 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528axios\u5e93\u6765\u8fdb\u884c\u722c\u53d6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a const axios = require(&#8216;axios&#8217;); async function getGoods() { const res = await axios.get(&#8216;https:\/\/www.58moto.com\/used-car\/1470264&#8217;); const html = res.data; console.log(html); } getGoods(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528axios\u722c\u53d6\u7f51\u9875\u65f6\uff0c\u8fd4\u56de\u7684body\u5df2\u7ecf\u7ecf\u8fc7\u4e86\u89e3\u7801\u5904\u7406\uff0c\u56e0\u6b64\u6253\u5370\u7684\u7ed3\u679c\u53ef\u4ee5\u6b63\u5e38\u663e\u793a\u3002 \u4ee5\u4e0a\u5c31\u662fNode.js\u722c\u53d6\u7f51\u9875\u7f16\u7801\u5f02\u5e38\u5982\u4f55\u89e3\u51b3\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-27527","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27527","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=27527"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27527\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}