{"id":1130,"date":"2026-07-02T09:55:20","date_gmt":"2026-07-02T01:55:20","guid":{"rendered":"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/web-scraping-javascript-guide\/"},"modified":"2026-07-02T09:55:20","modified_gmt":"2026-07-02T01:55:20","slug":"web-scraping-javascript-guide","status":"publish","type":"post","link":"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/web-scraping-javascript-guide\/","title":{"rendered":"JavaScript \u7f51\u9875\u722c\u866b\u6559\u7a0b\uff1a\u7528 JS \u91c7\u96c6\u52a8\u6001\u7f51\u9875\u6570\u636e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Python \u4e0d\u662f\u552f\u4e00\u80fd\u505a\u722c\u866b\u7684\u8bed\u8a00\u2014\u2014JavaScript\uff08Node.js\uff09\u5728\u722c\u866b\u9886\u57df\u540c\u6837\u5f3a\u5927\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u662f\u524d\u7aef\u5f00\u53d1\u8005\uff0c\u7528 JS \u505a\u722c\u866b\u53ef\u4ee5\u96f6\u8bed\u8a00\u5207\u6362\u6210\u672c\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u7840\u5de5\u5177\u94fe<\/h2>\n<pre class=\"wp-block-code\"><code>npm install axios cheerio puppeteer<\/code><\/pre>\n<p class=\"wp-block-paragraph\"><strong>axios<\/strong>\uff1aHTTP \u8bf7\u6c42\uff1b<strong>cheerio<\/strong>\uff1a\u670d\u52a1\u7aef jQuery\uff0c\u89e3\u6790 HTML\uff1b<strong>puppeteer<\/strong>\uff1aHeadless Chrome \u63a7\u5236\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u9759\u6001\u9875\u9762\u91c7\u96c6<\/h2>\n<pre class=\"wp-block-code\"><code>const axios = require('axios');\nconst cheerio = require('cheerio');\n\nasync function scrape(url) {\n  const { data } = await axios.get(url, {\n    headers: {'User-Agent': 'Mozilla\/5.0...'}\n  });\n  const $ = cheerio.load(data);\n  $('h2').each((i, el) => console.log($(el).text()));\n}<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u52a8\u6001\u9875\u9762\u91c7\u96c6\uff08Puppeteer\uff09<\/h2>\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\n\nasync function scrapeDynamic(url) {\n  const browser = await puppeteer.launch({headless: true});\n  const page = await browser.newPage();\n  await page.goto(url, {waitUntil: 'networkidle0'});\n  const content = await page.content();\n  await browser.close();\n  return content;\n}<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">JS vs Python \u722c\u866b<\/h2>\n<ul class=\"wp-block-list\">\n<li>JS \u5929\u7136\u9002\u5408\u5904\u7406 Web \u6570\u636e\uff0cJSON \u5904\u7406\u6700\u6d41\u7545<\/li>\n<li>Puppeteer > Python Selenium\uff08\u539f\u751f Chrome \u63a7\u5236\uff09<\/li>\n<li>Python \u751f\u6001\u66f4\u6210\u719f\uff0cScrapy \u65e0\u53ef\u66ff\u4ee3<\/li>\n<li>\u9009\u4f60\u719f\u6089\u7684\u8bed\u8a00\u2014\u2014\u4e24\u8005\u90fd\u80fd\u5b8c\u6210\u5de5\u4f5c<\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">\u76f8\u5173\u6559\u7a0b<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/python-web-scraper-tutorial\/\">Python \u722c\u866b\u5165\u95e8\u6559\u7a0b<\/a><\/li>\n<li><a href=\"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/headless-browser-guide\/\">\u65e0\u5934\u6d4f\u89c8\u5668\u5b8c\u5168\u6307\u5357<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Python \u4e0d\u662f\u552f\u4e00\u80fd\u505a\u722c\u866b\u7684\u8bed\u8a00\u2014\u2014JavaScript\uff08Node.js\uff09\u5728\u722c\u866b\u9886\u57df\u540c\u6837\u5f3a\u5927\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u662f\u524d\u7aef\u5f00\u53d1\u8005&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1130","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts\/1130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/comments?post=1130"}],"version-history":[{"count":0,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts\/1130\/revisions"}],"wp:attachment":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/media?parent=1130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/categories?post=1130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/tags?post=1130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}