[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-cn-nodejs-shiyong-daili":3},{"success":4,"payload":5,"related":81,"errors":151},true,{"id":6,"slug":7,"title":8,"excerpt":9,"body_html":10,"meta_title":11,"meta_description":12,"canonical_url":13,"canonical_override":14,"og_title":8,"og_description":12,"og_image_url":15,"faq_json":16,"key_takeaways":32,"allow_index":38,"noindex_google_only":38,"allow_follow":4,"published_at":39,"updated_at":40,"content_updated_at":41,"featured_image_url":42,"featured_image_alt":14,"card_image_url":43,"reading_time_minutes":44,"author":45,"categories":49,"tags":55,"alternates":67,"locale_paths":79,"views":80},4,"nodejs-shiyong-daili","在Node.js中使用代理（Axios + Puppeteer + SDK）","学习如何与Axios,Puppeteer,Playwright,以及ProxyHat SDK在Node.js中配置代理. 包括旋转、地理瞄准、重试和同时刮刮的代码示例.","\u003Ch2>为什么在Node.js中使用代理?\u003C\u002Fh2>\u003Cp>节点(Node.js)是最受欢迎的运行时间之一,用于建造网络刮刮器,API集成器,以及自动化工具. 但是,如果你从一个IP地址发送上百或上千个请求,你将很快会遇到利率限制,CAPTCHA,以及彻底的IP禁令. \u003Cstrong>节点中的代理\u003C\u002Fstrong> 解决这个问题的方法是通过不同的IP地址来引导您的请求,使每个请求看起来都来自一个独特的用户.\u003C\u002Fp>\u003Cp>无论是在刮掉产品价格,监测搜索引擎排名,还是大规模收集公共数据,代理都是必不可少的基础设施. 在本指南中,我们将涵盖所有你需要的将住宅代理纳入你的节点.js项目。 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FProxyHatCom\u002Fnode-sdk\" rel=\"noopener noreferrer\">代理节点 SDK\u003C\u002Fa>Axios, Puppeteer, 和 Playwright. (英语).\u003C\u002Fp>\u003Cp>如果您仍在评估哪个代理类型适合您的使用大小写, 请检查我们的比较 \u003Ca href=\"\u002Fcn\u002Fblog\u002Fzhuzhai-vs-shujuzhongxin-vs-yidong-daili\">住宅对数据中心对移动代理\u003C\u002Fa>。 。 。\u003C\u002Fp>\u003Ch2>安装和设置\u003C\u002Fh2>\u003Ch3>安装代理Hat SDK\u003C\u002Fh3>\u003Cp>最快的开始方式是官方的节点SDK：它用您的 API 密钥返回活跃子用户的代理 URL，可直接交给您的 HTTP 客户端：\u003C\u002Fp>\u003Cpre>\u003Ccode>npm install proxyhat\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>您还想要您计划使用的 HTTP 客户端 :\u003C\u002Fp>\u003Cpre>\u003Ccode>npm install axios puppeteer playwright undici https-proxy-agent\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>认证\u003C\u002Fh3>\u003Cp>所有代理连接通过您的 API 认证 。 您可以在 \u003Ca href=\"https:\u002F\u002Fdocs.proxyhat.com\u002F\" rel=\"noopener noreferrer\">代理哈特仪表板\u003C\u002Fa>。SDK 则使用 API 密钥认证，通过构造函数选项传入（也可从环境变量读取）：\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F Option 1: Pass the API key directly\nconst { ProxyHat } = require('proxyhat');\nconst client = new ProxyHat({\n  apiKey: 'ph_your_api_key',\n});\n\u002F\u002F Option 2: Read the API key from an environment variable\n\u002F\u002F Set PROXYHAT_API_KEY in your .env, then:\n\u002F\u002F const client = new ProxyHat({ apiKey: process.env.PROXYHAT_API_KEY });\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>简单 请求 SDK\u003C\u002Fh2>\u003Cp>SDK 通过 \u003Ccode>connectionUrl()\u003C\u002Fcode> 返回代理 URL，请求由 \u003Ccode>undici\u003C\u002Fcode> 的 \u003Ccode>fetch\u003C\u002Fcode> 发送：\u003C\u002Fp>\u003Cpre>\u003Ccode>const { ProxyHat } = require('proxyhat');\nconst { fetch, ProxyAgent } = require('undici');\nconst client = new ProxyHat({ apiKey: 'ph_your_api_key' });\nasync function main() {\n  const proxyUrl = await client.connectionUrl({ country: 'us' });\n  const response = await fetch('https:\u002F\u002Fhttpbin.org\u002Fip', {\n    dispatcher: new ProxyAgent(proxyUrl),\n  });\n  console.log('Status:', response.status);\n  console.log('Body:', await response.text());\n}\nmain().catch(console.error);\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>住宅代理默认轮换：每个新连接使用不同的 IP。不需要手动拼接代理 URL。\u003C\u002Fp>\u003Ch2>使用带有 Axios 的代理\u003C\u002Fh2>\u003Cp>Axios是Node.js生态系统中最受欢迎的HTTP客户端. 要将 Axios 请求通过 ProxyHat 路径,您可以直接使用 SDK 的代理 URL 或配置 Axios 。\u003C\u002Fp>\u003Ch3>方法1: axios 搭配 HTTPS 代理 Agent\u003C\u002Fh3>\u003Cpre>\u003Ccode>const { ProxyHat } = require('proxyhat');\nconst axios = require('axios');\nconst { HttpsProxyAgent } = require('https-proxy-agent');\nconst client = new ProxyHat({ apiKey: 'ph_your_api_key' });\nasync function scrapeWithAxios() {\n  const proxyUrl = await client.connectionUrl({ country: 'us' });\n  const agent = new HttpsProxyAgent(proxyUrl);\n  const response = await axios.get('https:\u002F\u002Fhttpbin.org\u002Fip', {\n    httpsAgent: agent,\n    proxy: false,\n    timeout: 30000,\n  });\n  console.log('IP:', response.data.origin);\n}\nscrapeWithAxios();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>方法2:直接代理 URL\u003C\u002Fh3>\u003Cp>如果您更喜欢手动配置, 请使用标准代理 URL 格式与 \u003Ccode>https-proxy-agent\u003C\u002Fcode> 软件包 :\u003C\u002Fp>\u003Cpre>\u003Ccode>const axios = require('axios');\nconst { HttpsProxyAgent } = require('https-proxy-agent');\nconst proxyUrl = 'http:\u002F\u002FUSERNAME:PASSWORD@gate.proxyhat.com:8080';\nconst agent = new HttpsProxyAgent(proxyUrl);\nasync function scrapeWithAxios() {\n  const response = await axios.get('https:\u002F\u002Fhttpbin.org\u002Fip', {\n    httpsAgent: agent,\n    timeout: 30000,\n  });\n  console.log('IP:', response.data.origin);\n}\nscrapeWithAxios();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>带有默认代理的 Axios 实例\u003C\u002Fh3>\u003Cp>对于重复使用,创建预配置的 Axios 实例 :\u003C\u002Fp>\u003Cpre>\u003Ccode>const { HttpsProxyAgent } = require('https-proxy-agent');\nconst agent = new HttpsProxyAgent('http:\u002F\u002FUSERNAME:PASSWORD@gate.proxyhat.com:8080');\nconst proxyClient = axios.create({\n  httpsAgent: agent,\n  timeout: 30000,\n  headers: {\n    'User-Agent': 'Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\u002F537.36',\n  },\n});\n\u002F\u002F All requests now go through the proxy\nconst res = await proxyClient.get('https:\u002F\u002Fexample.com');\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>使用带有 Puppeteer 的代理\u003C\u002Fh2>\u003Cp>Puppeteer推出一个无头Chrome浏览器,这是刮掉JavaScript-havy网站的理想. 代理配置在浏览器发布级别.\u003C\u002Fp>\u003Cpre>\u003Ccode>const puppeteer = require('puppeteer');\nasync function scrapeWithPuppeteer() {\n  const browser = await puppeteer.launch({\n    args: ['--proxy-server=gate.proxyhat.com:8080'],\n    headless: 'new',\n  });\n  const page = await browser.newPage();\n  \u002F\u002F Authenticate with the proxy\n  await page.authenticate({\n    username: 'USERNAME',\n    password: 'PASSWORD',\n  });\n  await page.goto('https:\u002F\u002Fhttpbin.org\u002Fip', {\n    waitUntil: 'networkidle2',\n    timeout: 60000,\n  });\n  const content = await page.evaluate(() => document.body.innerText);\n  console.log('IP:', content);\n  await browser.close();\n}\nscrapeWithPuppeteer();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>带有地理目标的傀儡\u003C\u002Fh3>\u003Cp>要针对特定国家,请在您的用户名中加入国家代码。 代理服务器使用格式 \u003Ccode>USERNAME-country-XX\u003C\u002Fcode>编号 :\u003C\u002Fp>\u003Cpre>\u003Ccode>await page.authenticate({\n  username: 'USERNAME-country-de',  \u002F\u002F Route through Germany\n  password: 'PASSWORD',\n});\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>浏览我们所有可用的代理地址 \u003Ca href=\"\u002Fcn\u002Flocations\">地点页面\u003C\u002Fa>。 。 。\u003C\u002Fp>\u003Ch2>使用带有 Playwright 的代理\u003C\u002Fh2>\u003Cp>Playwright支持Chrimium,Firefox,和WebKit. 星洲网. 代理配置被构建在发射选项中,使其更加简单:\u003C\u002Fp>\u003Cpre>\u003Ccode>const { chromium } = require('playwright');\nasync function scrapeWithPlaywright() {\n  const browser = await chromium.launch({\n    proxy: {\n      server: 'http:\u002F\u002Fgate.proxyhat.com:8080',\n      username: 'USERNAME',\n      password: 'PASSWORD',\n    },\n  });\n  const context = await browser.newContext();\n  const page = await context.newPage();\n  await page.goto('https:\u002F\u002Fhttpbin.org\u002Fip');\n  const body = await page.textContent('body');\n  console.log('IP:', body);\n  await browser.close();\n}\nscrapeWithPlaywright();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>带有 per- Context 代理 的 Playwright\u003C\u002Fh3>\u003Cp>Playwright 每个浏览器上下文允许不同的代理,这对多账户或多区域刮切有用:\u003C\u002Fp>\u003Cpre>\u003Ccode>const browser = await chromium.launch();\n\u002F\u002F US context\nconst usContext = await browser.newContext({\n  proxy: {\n    server: 'http:\u002F\u002Fgate.proxyhat.com:8080',\n    username: 'USERNAME-country-us',\n    password: 'PASSWORD',\n  },\n});\n\u002F\u002F UK context\nconst ukContext = await browser.newContext({\n  proxy: {\n    server: 'http:\u002F\u002Fgate.proxyhat.com:8080',\n    username: 'USERNAME-country-gb',\n    password: 'PASSWORD',\n  },\n});\nconst usPage = await usContext.newPage();\nconst ukPage = await ukContext.newPage();\nawait Promise.all([\n  usPage.goto('https:\u002F\u002Fwww.google.com\u002Fsearch?q=proxy+service'),\n  ukPage.goto('https:\u002F\u002Fwww.google.co.uk\u002Fsearch?q=proxy+service'),\n]);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>旋转对粘性会话\u003C\u002Fh2>\u003Cp>代理Hat支持满足不同刮切需求的两种会话模式:\u003C\u002Fp>\u003Ctable>\n\u003Ccaption>旋转对粘性会话\u003C\u002Fcaption>\u003Cthead>\u003Ctr>\u003Cth>特性\u003C\u002Fth>\u003Cth>旋转\u003C\u002Fth>\u003Cth>粘着\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>每个请求的IP\u003C\u002Ftd>\u003Ctd>每次新建 IP\u003C\u002Ftd>\u003Ctd>会话持续时间相同 IP\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>最佳办法\u003C\u002Ftd>\u003Ctd>大规模刮刮\u003C\u002Ftd>\u003Ctd>多步骤工作流程、登录会话\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>会期\u003C\u002Ftd>\u003Ctd>不详\u003C\u002Ftd>\u003Ctd>最多30分钟\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>用户名格式\u003C\u002Ftd>\u003Ctd>\u003Ccode>USERNAME\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>\u003Ccode>USERNAME-sid-XXXX\u003C\u002Fcode>\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch3>粘贴会话示例\u003C\u002Fh3>\u003Cpre>\u003Ccode>const { HttpsProxyAgent } = require('https-proxy-agent');\nconst axios = require('axios');\n\u002F\u002F Generate a random session ID\nconst sessionId = 'session_' + Math.random().toString(36).slice(2, 10);\nconst agent = new HttpsProxyAgent(\n  `http:\u002F\u002FUSERNAME-sid-${sessionId}:PASSWORD@gate.proxyhat.com:8080`\n);\n\u002F\u002F All requests with this agent use the same IP\nconst client = axios.create({ httpsAgent: agent, timeout: 30000 });\nconst res1 = await client.get('https:\u002F\u002Fhttpbin.org\u002Fip');\nconst res2 = await client.get('https:\u002F\u002Fhttpbin.org\u002Fip');\nconsole.log(res1.data.origin === res2.data.origin); \u002F\u002F true\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>地理目标请求\u003C\u002Fh2>\u003Cp>地理目标对于 \u003Ca href=\"\u002Fcn\u002Fuse-cases\u002Fserp-tracking\">SERP 跟踪\u003C\u002Fa>、当地价格监测以及区域内容核查。 PoxyHat 通过您的用户名字符串支持国家级别和城市级别的目标:\u003C\u002Fp>\u003Cpre>\u003Ccode>\u002F\u002F Country targeting\nconst countryAgent = new HttpsProxyAgent(\n  'http:\u002F\u002FUSERNAME-country-jp:PASSWORD@gate.proxyhat.com:8080'\n);\n\u002F\u002F City targeting\nconst cityAgent = new HttpsProxyAgent(\n  'http:\u002F\u002FUSERNAME-country-us-region-new_york-city-new_york_city:PASSWORD@gate.proxyhat.com:8080'\n);\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>请检查date=中的日期值 (帮助) \u003Ca href=\"\u002Fcn\u002Flocations\">可用地点\u003C\u002Fa> 支助国家和城市。\u003C\u002Fp>\u003Ch2>处理和检索错误\u003C\u002Fh2>\u003Cp>网络错误在规模化与代理合作时是不可避免的. 强有力的再试验战略对废品生产至关重要:\u003C\u002Fp>\u003Cpre>\u003Ccode>const axios = require('axios');\nconst { HttpsProxyAgent } = require('https-proxy-agent');\nasync function fetchWithRetry(url, options = {}) {\n  const maxRetries = options.maxRetries || 3;\n  const baseDelay = options.baseDelay || 1000;\n  for (let attempt = 1; attempt \u003C= maxRetries; attempt++) {\n    try {\n      const agent = new HttpsProxyAgent(\n        'http:\u002F\u002FUSERNAME:PASSWORD@gate.proxyhat.com:8080'\n      );\n      const response = await axios.get(url, {\n        httpsAgent: agent,\n        timeout: options.timeout || 30000,\n      });\n      if (response.status === 200) return response;\n      throw new Error(`HTTP ${response.status}`);\n    } catch (error) {\n      console.warn(`Attempt ${attempt}\u002F${maxRetries} failed: ${error.message}`);\n      if (attempt === maxRetries) throw error;\n      \u002F\u002F Exponential backoff: 1s, 2s, 4s...\n      const delay = baseDelay * Math.pow(2, attempt - 1);\n      await new Promise(r => setTimeout(r, delay));\n    }\n  }\n}\n\u002F\u002F Usage\nconst response = await fetchWithRetry('https:\u002F\u002Fexample.com', {\n  maxRetries: 3,\n  timeout: 20000,\n});\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>与货币控制同步擦拭\u003C\u002Fh2>\u003Cp>立即发送所有请求 \u003Ccode>Promise.all\u003C\u002Fcode> 可以覆盖你的机器和目标服务器。 使用货币限制器控制并行连接的数目 :\u003C\u002Fp>\u003Cpre>\u003Ccode>async function asyncPool(concurrency, items, iteratorFn) {\n  const results = [];\n  const executing = new Set();\n  for (const [index, item] of items.entries()) {\n    const promise = Promise.resolve().then(() => iteratorFn(item, index));\n    results.push(promise);\n    executing.add(promise);\n    const cleanup = () => executing.delete(promise);\n    promise.then(cleanup, cleanup);\n    if (executing.size >= concurrency) {\n      await Promise.race(executing);\n    }\n  }\n  return Promise.all(results);\n}\n\u002F\u002F Scrape 100 URLs, 10 at a time\nconst urls = Array.from({ length: 100 }, (_, i) =>\n  `https:\u002F\u002Fexample.com\u002Fpage\u002F${i + 1}`\n);\nconst results = await asyncPool(10, urls, async (url) => {\n  return fetchWithRetry(url, { maxRetries: 2, timeout: 15000 });\n});\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>用于大型 \u003Ca href=\"\u002Fcn\u002Fuse-cases\u002Fweb-scraping\">网络刮除项目\u003C\u002Fa>在速度和可靠性之间保持了良好的平衡。 阅读我们的指南 \u003Ca href=\"\u002Fcn\u002Fblog\u002Fzuijia-wangluo-caiji-daili-2026\">2026年网络刮刮的最佳代理\u003C\u002Fa> 更多的建筑建议。\u003C\u002Fp>\u003Ch2>制作提示\u003C\u002Fh2>\u003Ch3>连接管理\u003C\u002Fh3>\u003Cul>\u003Cli>重复使用 Axios 实例和代理代理代理,而不是每个请求创建新的代理代理代理 。 这样可以避免套接字耗尽。\u003C\u002Fli>\u003Cli>设定 \u003Ccode>keepAlive: true\u003C\u002Fcode> 在您的 HTTP 代理中持续连接 。\u003C\u002Fli>\u003Cli>使用后迅速关闭Pippeteer\u002FPlaywright浏览器以释放内存.\u003C\u002Fli>\u003C\u002Ful>\u003Ch3>内存和超时\u003C\u002Fh3>\u003Cul>\u003Cli>对于傀儡,使用 \u003Ccode>page.setRequestInterception(true)\u003C\u002Fcode> 当您只需要 HTML 内容时,可以屏蔽图像、 CSS 和字体。 这大大降低了带宽和内存的使用.\u003C\u002Fli>\u003Cli>总是为每个请求设定明确的超时. 缺时是吊刮器的头号原因。\u003C\u002Fli>\u003Cli>监视节点.js内存 \u003Ccode>process.memoryUsage()\u003C\u002Fcode> 在长期刮刮机。\u003C\u002Fli>\u003C\u002Ful>\u003Ch3>请求截取更快的搜索\u003C\u002Fh3>\u003Cpre>\u003Ccode>const page = await browser.newPage();\nawait page.setRequestInterception(true);\npage.on('request', (req) => {\n  const blocked = ['image', 'stylesheet', 'font', 'media'];\n  if (blocked.includes(req.resourceType())) {\n    req.abort();\n  } else {\n    req.continue();\n  }\n});\nawait page.goto('https:\u002F\u002Fexample.com');\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>环境变量\u003C\u002Fh3>\u003Cp>从来没有硬码证书。 使用一个 \u003Ccode>.env\u003C\u002Fcode> 文件并装入 \u003Ccode>dotenv\u003C\u002Fcode>编号 :\u003C\u002Fp>\u003Cpre>\u003Ccode>require('dotenv').config();\nconst proxyUrl = `http:\u002F\u002F${process.env.PROXY_USER}:${process.env.PROXY_PASS}@gate.proxyhat.com:8080`;\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>准备好了吗? 检查 \u003Ca href=\"\u002Fcn\u002Fpricing\">我们的定价计划\u003C\u002Fa> 以找到您工程的适量住宅代理带宽。\u003C\u002Fp>\u003Cblockquote>\u003Ch3>关键外卖\u003C\u002Fh3>\u003Cul>\u003Cli>这个 \u003Cstrong>代理节点 SDK\u003C\u002Fstrong> 是添加代理支持的最快方式。 安装方式 \u003Ccode>npm install proxyhat\u003C\u002Fcode> 并开始以三行代码获取。\u003C\u002Fli>\u003Cli>\u003Cstrong>轴线\u003C\u002Fstrong> 通过 \u003Ccode>https-proxy-agent\u003C\u002Fcode> 或者SDK返回的代理 URL。 创建可重复使用的 Axios 实例以提高效率 。\u003C\u002Fli>\u003Cli>\u003Cstrong>傀儡\u003C\u002Fstrong> 接受代理作为发射参数。 调用 \u003Ccode>page.authenticate()\u003C\u002Fcode> 通过全权证书。\u003C\u002Fli>\u003Cli>\u003Cstrong>剧作家\u003C\u002Fstrong> 在其启动和上下文选项中拥有本地代理支持,包括多区域拆解的内文本代理。\u003C\u002Fli>\u003Cli>使用 粘贴会议 多步骤工作流程和 旋转 IP 用于大规模数据收集。\u003C\u002Fli>\u003Cli>总是执行 用指数反转重试逻辑 和 货币控制 在生产废料。\u003C\u002Fli>\u003Cli>在无头浏览器中屏蔽不必要的资源以减少带宽和提高速度.\u003C\u002Fli>\u003C\u002Ful>\u003C\u002Fblockquote>","Node.js代理使用指南：Axios + Puppetee","在Node.js中集成代理的完整指南。使用Axios、Puppeteer和ProxyHat SDK实现代理轮换、浏览器自动化和大规模爬取的代码示例。","\u002Fcn\u002Fblog\u002Fnodejs-shiyong-daili",null,"https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fnodejs-shiyong-daili-og.webp",[17,20,23,26,29],{"question":18,"answer":19},"如何在Node.js的Axios中使用代理？","使用proxy配置选项或通过https-proxy-agent库设置。ProxyHat Node SDK 的 client.connectionUrl() 可直接返回代理 URL，进一步简化了配置；轮换由网关完成。",{"question":21,"answer":22},"如何在Puppeteer中设置代理？","在puppeteer.launch()中使用--proxy-server参数：args: [\"--proxy-server=http:\u002F\u002Fgate.proxyhat.com:8080\"]。然后通过page.authenticate()方法提供用户名和密码进行身份验证。",{"question":24,"answer":25},"Node.js中如何实现代理轮换？","使用ProxyHat SDK时，connectionUrl() 默认返回轮换代理，每个请求自动更换IP。手动实现时，可以维护一个代理列表并为每个请求随机选择，或使用ProxyHat的网关地址gate.proxyhat.com:8080，每次连接自动分配不同IP。",{"question":27,"answer":28},"在Node.js中应该用Axios还是Puppeteer配合代理？","Axios适合简单的HTTP请求和API调用——速度快且资源消耗少。Puppeteer适合需要JavaScript渲染的网站——它运行完整的浏览器来执行JS并加载动态内容。对于大多数爬取任务，先尝试Axios，仅在目标需要JS渲染时才使用Puppeteer。",{"question":30,"answer":31},"如何在Node.js爬虫中处理代理超时？","在Axios中设置timeout选项（建议30秒），在Puppeteer中使用page.setDefaultTimeout()。实现带指数退避的重试逻辑，并在多次失败后切换到新的代理IP。ProxyHat SDK 只返回代理 URL，重试和超时需在 HTTP 客户端中配置。",[33,34,35,36,37],"在Node.js中使用代理可避免IP封禁和速率限制，ProxyHat SDK 可用 API 密钥直接获取轮换代理的 URL，是快速集成代理的便捷方式。","Axios可通过https-proxy-agent配合SDK返回的代理URL配置请求，建议创建可复用的实例以提高效率。","Puppeteer和Playwright在浏览器启动级别支持代理配置，并能通过用户名格式实现地理定位和多区域抓取。","生产环境中应使用粘性会话处理多步骤工作流，用旋转IP进行大规模抓取，并配合指数退避重试和并发控制。","优化建议：在无头浏览器中屏蔽图片等不必要资源以降低带宽，并使用环境变量管理代理凭证以保安全。",false,"2026-01-06T09:05:38+00:00","2026-07-19T03:13:07+00:00","2026-11-17T10:40:54+00:00","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fnodejs-shiyong-daili-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fnodejs-shiyong-daili-card.webp",12,{"name":46,"slug":47,"bio":48,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[50],{"id":6,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},"kaifa-zhinan","开发者指南","开发者指南 | ProxyHat 博客","代码教程和SDK指南，帮助您将代理集成到应用程序中。",[56,60,64],{"id":57,"slug":58,"name":59},1,"web-scraping","网页抓取",{"id":61,"slug":62,"name":63},10,"nodejs","Node.js",{"id":44,"slug":65,"name":66},"sdk","SDK",{"pt":68,"de":69,"es":70,"tr":71,"en":72,"ru":73,"ja":74,"pl":75,"ko":76,"it":77,"zh":13,"fr":78,"x-default":72},"\u002Fpt\u002Fblog\u002Fusando-proxies-em-nodejs","\u002Fde\u002Fblog\u002Fproxies-in-nodejs-verwenden","\u002Fes\u002Fblog\u002Fusar-proxies-en-nodejs","\u002Ftr\u002Fblog\u002Fnodejs-ile-proxy-kullanimi","\u002Fblog\u002Fusing-proxies-in-nodejs","\u002Fru\u002Fblog\u002Fispolzovanie-proksi-v-nodejs","\u002Fja\u002Fblog\u002Fnodejs-de-prokishi-wo-tsukau","\u002Fpl\u002Fblog\u002Fkorzystanie-z-proxies-w-nodejs-axios-puppeteer-sdk","\u002Fko\u002Fblog\u002Fnodejs-proxy-sayongbeop","\u002Fit\u002Fblog\u002Futilizzo-dei-proxy-in-nodejs-axios-puppeteer-sdk","\u002Ffr\u002Fblog\u002Futiliser-des-proxies-en-nodejs",{"pt":68,"de":69,"es":70,"tr":71,"en":72,"ru":73,"ja":74,"pl":75,"ko":76,"it":77,"zh":13,"fr":78},78,[82,99,117,135],{"id":83,"slug":84,"title":85,"excerpt":86,"featured_image_url":87,"featured_image_alt":14,"card_image_url":88,"og_image_url":89,"published_at":90,"updated_at":40,"content_updated_at":91,"reading_time_minutes":44,"is_featured":38,"indexable":38,"views":92,"author":93,"categories":94,"tags":96},50,"sheji-kekaode-caiji-jiagou","设计可靠的网络爬虫架构","设计端到端的刮刮系统:排程器,URL队列,爬行器池,代理层,剖析器,存储,以及监控. 生产准备的 Python 代码与建筑图.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fsheji-kekaode-caiji-jiagou-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fsheji-kekaode-caiji-jiagou-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fsheji-kekaode-caiji-jiagou-og.webp","2026-02-24T06:55:16+00:00","2026-10-03T08:21:25+00:00",73,{"name":46,"slug":47,"bio":48,"avatar_url":14,"website_url":14,"social_links":14},[95],{"id":6,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[97,98],{"id":44,"slug":65,"name":66},{"id":57,"slug":58,"name":59},{"id":100,"slug":101,"title":102,"excerpt":103,"featured_image_url":104,"featured_image_alt":14,"card_image_url":105,"og_image_url":106,"published_at":107,"updated_at":40,"content_updated_at":108,"reading_time_minutes":109,"is_featured":38,"indexable":38,"views":110,"author":111,"categories":112,"tags":114},41,"jiankong-daili-xingneng","监控代理性能：延迟、成功率和告警","学习如何对代理性能进行仪表、监控和警报——跟踪延迟百分位数、成功率、错误模式和带宽。 Python、Node.js和Go的代码示例.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fjiankong-daili-xingneng-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fjiankong-daili-xingneng-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fjiankong-daili-xingneng-og.webp","2026-02-15T00:39:23+00:00","2026-10-03T08:21:24+00:00",11,77,{"name":46,"slug":47,"bio":48,"avatar_url":14,"website_url":14,"social_links":14},[113],{"id":6,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[115,116],{"id":44,"slug":65,"name":66},{"id":57,"slug":58,"name":59},{"id":118,"slug":119,"title":120,"excerpt":121,"featured_image_url":122,"featured_image_alt":14,"card_image_url":123,"og_image_url":124,"published_at":125,"updated_at":40,"content_updated_at":126,"reading_time_minutes":61,"is_featured":38,"indexable":38,"views":83,"author":127,"categories":128,"tags":132},36,"kuozhan-caiji-jiagou","如何扩展网络爬虫基础设施","缩放网刮的架构模式:基于队列的系统,管道设计,带容器的横向缩放,以及规模化的代理管理. 代码在Python,Node.js,和去.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-caiji-jiagou-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-caiji-jiagou-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-caiji-jiagou-og.webp","2026-02-09T14:42:34+00:00","2026-02-26T00:33:08+00:00",{"name":46,"slug":47,"bio":48,"avatar_url":14,"website_url":14,"social_links":14},[129],{"id":57,"slug":58,"name":59,"description":14,"meta_title":130,"meta_description":131,"parent_id":14},"网页抓取指南 | ProxyHat 博客","网页抓取技术、代理策略和数据提取最佳实践。",[133,134],{"id":57,"slug":58,"name":59},{"id":44,"slug":65,"name":66},{"id":136,"slug":137,"title":138,"excerpt":139,"featured_image_url":140,"featured_image_alt":14,"card_image_url":141,"og_image_url":142,"published_at":143,"updated_at":40,"content_updated_at":108,"reading_time_minutes":44,"is_featured":38,"indexable":38,"views":144,"author":145,"categories":146,"tags":148},35,"kuozhan-daili-qingqiu-bingfa-kongzhi","使用并发控制扩展代理请求","用于代理式刮刮的主货币图案:Ayncio semaphores,承诺池,Go工人池,限速器,以及反压. Python、Node.js和Go的生产代码.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-daili-qingqiu-bingfa-kongzhi-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-daili-qingqiu-bingfa-kongzhi-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fkuozhan-daili-qingqiu-bingfa-kongzhi-og.webp","2026-02-08T11:16:13+00:00",362,{"name":46,"slug":47,"bio":48,"avatar_url":14,"website_url":14,"social_links":14},[147],{"id":6,"slug":51,"name":52,"description":14,"meta_title":53,"meta_description":54,"parent_id":14},[149,150],{"id":44,"slug":65,"name":66},{"id":57,"slug":58,"name":59},[]]