[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-cn-caiji-javascript-zhongdu-wangzhan":3},{"success":4,"payload":5,"related":88,"errors":206},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":44,"allow_index":50,"noindex_google_only":50,"allow_follow":4,"published_at":51,"updated_at":52,"content_updated_at":53,"featured_image_url":54,"featured_image_alt":14,"card_image_url":55,"reading_time_minutes":56,"author":57,"categories":61,"tags":68,"alternates":74,"locale_paths":86,"views":87},47,"caiji-javascript-zhongdu-wangzhan","如何爬取JavaScript重度渲染的网站","Scrape JavaScript - 以无头浏览器和代理方式提交内容. Puppeteer, Playwright, 和chromedp 设置指南 具有性能优化和 API 截取策略.","\u003Ch2>JavaScript- 渲染内容的挑战\u003C\u002Fh2>\u003Cp>现代网站越来越依赖JavaScript来渲染内容. 单页应用程序(SPA)用React,Vue,或Angular装入一个最小的HTML shell,然后获取和渲染数据客户端侧. 当向这些站点提出简单的HTTP请求时,会得到一个空的或不完整的页面,因为内容只在JavaScript执行后才存在.\u003C\u002Fp>\u003Cp>搜索 JavaScript 重置网站需要 \u003Cstrong>无头浏览器\u003C\u002Fstrong> ——真实的浏览器引擎运行时没有可见的窗口,可以执行JavaScript,渲染DOM,并与页面元素交互. 结合代理,无头浏览器解锁甚至最动态网站的数据.\u003C\u002Fp>\u003Cblockquote>这个向导是我们的一部分 \u003Ca href=\"\u002Fcn\u002Fblog\u002Fwangluo-caiji-daili-wanzheng-zhinan\">完整网页搜索代理指南\u003C\u002Fa>为避免在使用无头浏览器时检测,请参见 \u003Ca href=\"\u002Fcn\u002Fblog\u002Ffan-jiqi-ren-xitong-ruhe-jiance-daili\">反毒系统如何检测代理\u003C\u002Fa>。 。 。\u003C\u002Fblockquote>\u003Ch2>您何时需要无头浏览器 ?\u003C\u002Fh2>\u003Ctable>\n\u003Ccaption>您何时需要无头浏览器 ?\u003C\u002Fcaption>\u003Cthead>\u003Ctr>\u003Cth>假设\u003C\u002Fth>\u003Cth>简单 HTTP\u003C\u002Fth>\u003Cth>无头浏览器\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>静态 HTML 页面\u003C\u002Ftd>\u003Ctd>完美无缺\u003C\u002Ftd>\u003Ctd>过度杀戮\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>用 API 发送服务器页面\u003C\u002Ftd>\u003Ctd>工程(直接击中API)\u003C\u002Ftd>\u003Ctd>无需\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>SPA (反应, Vue, 角)\u003C\u002Ftd>\u003Ctd>获取空 shell\u003C\u002Ftd>\u003Ctd>要求数\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>无限卷轴\u002F 懒惰装入\u003C\u002Ftd>\u003Ctd>无法触发\u003C\u002Ftd>\u003Ctd>要求数\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>登录后的内容 + JS\u003C\u002Ftd>\u003Ctd>困难\u003C\u002Ftd>\u003Ctd>建议\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>有反机器人JS检查的页面\u003C\u002Ftd>\u003Ctd>检测失败\u003C\u002Ftd>\u003Ctd>要求数\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Cblockquote>总是在到达无头浏览器前检查网站是否有API或服务器侧渲染. 许多\"JavaScript-havy\"网站实际上都有API端点,可以返回干净的JSON——可以更快,更便宜的刮刮.\u003C\u002Fblockquote>\u003Ch2>管道工+代理(节点.js)\u003C\u002Fh2>\u003Cp>Puppeteer在程序上控制着铬\u002F铬. 它是Node.js最成熟的无头浏览器工具.\u003C\u002Fp>\u003Ch3>基本设置, 使用代理汉特\u003C\u002Fh3>\u003Cpre>\u003Ccode>const puppeteer = require('puppeteer');\nasync function scrapeWithPuppeteer(url) {\n  const browser = await puppeteer.launch({\n    headless: 'new',\n    args: [\n      '--proxy-server=http:\u002F\u002Fgate.proxyhat.com:8080',\n      '--no-sandbox',\n      '--disable-setuid-sandbox',\n      '--disable-dev-shm-usage',\n    ],\n  });\n  const page = await browser.newPage();\n  \u002F\u002F Authenticate with proxy\n  await page.authenticate({\n    username: 'USERNAME',\n    password: 'PASSWORD',\n  });\n  \u002F\u002F Set realistic viewport and user agent\n  await page.setViewport({ width: 1920, height: 1080 });\n  await page.setUserAgent(\n    'Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\u002F537.36 ' +\n    '(KHTML, like Gecko) Chrome\u002F120.0.0.0 Safari\u002F537.36'\n  );\n  try {\n    await page.goto(url, { waitUntil: 'networkidle2', timeout: 60000 });\n    \u002F\u002F Wait for specific content to render\n    await page.waitForSelector('.product-list', { timeout: 10000 });\n    const content = await page.content();\n    const data = await page.evaluate(() => {\n      return Array.from(document.querySelectorAll('.product-item')).map(el => ({\n        name: el.querySelector('.product-name')?.textContent?.trim(),\n        price: el.querySelector('.product-price')?.textContent?.trim(),\n        url: el.querySelector('a')?.href,\n      }));\n    });\n    return { html: content, data };\n  } finally {\n    await browser.close();\n  }\n}\n\u002F\u002F Usage\nconst result = await scrapeWithPuppeteer('https:\u002F\u002Fexample.com\u002Fproducts');\nconsole.log(`Found ${result.data.length} products`);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>优化多页搜索\u003C\u002Fh3>\u003Cpre>\u003Ccode>const puppeteer = require('puppeteer');\nclass PuppeteerScraper {\n  constructor(concurrency = 3) {\n    this.concurrency = concurrency;\n    this.browser = null;\n  }\n  async init() {\n    this.browser = await puppeteer.launch({\n      headless: 'new',\n      args: [\n        '--proxy-server=http:\u002F\u002Fgate.proxyhat.com:8080',\n        '--no-sandbox',\n        '--disable-setuid-sandbox',\n        '--disable-dev-shm-usage',\n        '--disable-gpu',\n        '--disable-extensions',\n      ],\n    });\n  }\n  async scrapePage(url) {\n    const page = await this.browser.newPage();\n    await page.authenticate({ username: 'USERNAME', password: 'PASSWORD' });\n    await page.setViewport({ width: 1920, height: 1080 });\n    \u002F\u002F Block unnecessary resources to speed up loading\n    await page.setRequestInterception(true);\n    page.on('request', (req) => {\n      const type = req.resourceType();\n      if (['image', 'stylesheet', 'font', 'media'].includes(type)) {\n        req.abort();\n      } else {\n        req.continue();\n      }\n    });\n    try {\n      await page.goto(url, { waitUntil: 'networkidle2', timeout: 30000 });\n      const content = await page.content();\n      return { url, status: 'success', html: content };\n    } catch (err) {\n      return { url, status: 'error', error: err.message };\n    } finally {\n      await page.close();\n    }\n  }\n  async scrapeMany(urls) {\n    const results = [];\n    for (let i = 0; i \u003C urls.length; i += this.concurrency) {\n      const batch = urls.slice(i, i + this.concurrency);\n      const batchResults = await Promise.all(\n        batch.map(url => this.scrapePage(url))\n      );\n      results.push(...batchResults);\n      console.log(`Progress: ${results.length}\u002F${urls.length}`);\n    }\n    return results;\n  }\n  async close() {\n    if (this.browser) await this.browser.close();\n  }\n}\n\u002F\u002F Usage\nconst scraper = new PuppeteerScraper(3);\nawait scraper.init();\nconst results = await scraper.scrapeMany(urls);\nawait scraper.close();\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>Playwright + 代理 (Python) (英语).\u003C\u002Fh2>\u003Cp>Playwright是一个支持Chrimium,Firefox,和WebKit的较新的替代品. 它的Python API是干净的,适合刮刮.\u003C\u002Fp>\u003Ch3>基本设置\u003C\u002Fh3>\u003Cpre>\u003Ccode>from playwright.sync_api import sync_playwright\ndef scrape_with_playwright(url: str) -> dict:\n    \"\"\"Scrape a JavaScript-heavy page using Playwright with ProxyHat proxy.\"\"\"\n    with sync_playwright() as p:\n        browser = p.chromium.launch(\n            headless=True,\n            proxy={\n                \"server\": \"http:\u002F\u002Fgate.proxyhat.com:8080\",\n                \"username\": \"USERNAME\",\n                \"password\": \"PASSWORD\",\n            }\n        )\n        context = browser.new_context(\n            viewport={\"width\": 1920, \"height\": 1080},\n            user_agent=\"Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64) \"\n                       \"AppleWebKit\u002F537.36 (KHTML, like Gecko) \"\n                       \"Chrome\u002F120.0.0.0 Safari\u002F537.36\",\n        )\n        page = context.new_page()\n        try:\n            page.goto(url, wait_until=\"networkidle\", timeout=60000)\n            # Wait for dynamic content\n            page.wait_for_selector(\".product-list\", timeout=10000)\n            # Extract data using page.evaluate\n            products = page.evaluate(\"\"\"() => {\n                return Array.from(document.querySelectorAll('.product-item')).map(el => ({\n                    name: el.querySelector('.product-name')?.textContent?.trim(),\n                    price: el.querySelector('.product-price')?.textContent?.trim(),\n                    url: el.querySelector('a')?.href,\n                }));\n            }\"\"\")\n            return {\"url\": url, \"products\": products, \"html\": page.content()}\n        finally:\n            browser.close()\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>并行搜索的 Async Playwright\u003C\u002Fh3>\u003Cpre>\u003Ccode>import asyncio\nfrom playwright.async_api import async_playwright\nasync def scrape_batch(urls: list[str], concurrency: int = 3) -> list[dict]:\n    \"\"\"Scrape multiple JS-heavy pages in parallel using Playwright.\"\"\"\n    results = []\n    async with async_playwright() as p:\n        browser = await p.chromium.launch(\n            headless=True,\n            proxy={\n                \"server\": \"http:\u002F\u002Fgate.proxyhat.com:8080\",\n                \"username\": \"USERNAME\",\n                \"password\": \"PASSWORD\",\n            }\n        )\n        semaphore = asyncio.Semaphore(concurrency)\n        async def scrape_one(url: str) -> dict:\n            async with semaphore:\n                context = await browser.new_context(\n                    viewport={\"width\": 1920, \"height\": 1080},\n                )\n                page = await context.new_page()\n                # Block heavy resources\n                await page.route(\"**\u002F*.{png,jpg,jpeg,gif,svg,css,woff,woff2}\",\n                                 lambda route: route.abort())\n                try:\n                    await page.goto(url, wait_until=\"networkidle\", timeout=30000)\n                    html = await page.content()\n                    return {\"url\": url, \"status\": \"success\", \"html\": html}\n                except Exception as e:\n                    return {\"url\": url, \"status\": \"error\", \"error\": str(e)}\n                finally:\n                    await context.close()\n        tasks = [scrape_one(url) for url in urls]\n        results = await asyncio.gather(*tasks)\n        await browser.close()\n    return results\n# Usage\nurls = [f\"https:\u002F\u002Fexample.com\u002Fproduct\u002F{i}\" for i in range(50)]\nresults = asyncio.run(scrape_batch(urls, concurrency=5))\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>跳: 与代理使用色调\u003C\u002Fh2>\u003Cpre>\u003Ccode>package main\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n    \"time\"\n    \"github.com\u002Fchromedp\u002Fchromedp\"\n)\nfunc scrapeJSPage(targetURL string) (string, error) {\n    \u002F\u002F Configure proxy\n    opts := append(chromedp.DefaultExecAllocatorOptions[:],\n        chromedp.ProxyServer(\"http:\u002F\u002Fgate.proxyhat.com:8080\"),\n        chromedp.Flag(\"headless\", true),\n        chromedp.Flag(\"disable-gpu\", true),\n        chromedp.Flag(\"no-sandbox\", true),\n        chromedp.UserAgent(\"Mozilla\u002F5.0 (Windows NT 10.0; Win64; x64) \"+\n            \"AppleWebKit\u002F537.36 (KHTML, like Gecko) Chrome\u002F120.0.0.0 Safari\u002F537.36\"),\n    )\n    allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)\n    defer cancel()\n    ctx, cancel := chromedp.NewContext(allocCtx)\n    defer cancel()\n    ctx, cancel = context.WithTimeout(ctx, 60*time.Second)\n    defer cancel()\n    var htmlContent string\n    err := chromedp.Run(ctx,\n        chromedp.Navigate(targetURL),\n        chromedp.WaitVisible(\".product-list\", chromedp.ByQuery),\n        chromedp.OuterHTML(\"html\", &htmlContent),\n    )\n    if err != nil {\n        return \"\", fmt.Errorf(\"scrape failed: %w\", err)\n    }\n    return htmlContent, nil\n}\nfunc main() {\n    html, err := scrapeJSPage(\"https:\u002F\u002Fexample.com\u002Fproducts\")\n    if err != nil {\n        log.Fatal(err)\n    }\n    fmt.Printf(\"Got %d bytes of rendered HTML\\n\", len(html))\n}\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>业绩优化战略\u003C\u002Fh2>\u003Cp>无头浏览器比简单的HTTP请求慢10-50x. 以下是尽量减少业绩差距的战略:\u003C\u002Fp>\u003Ch3>1. 不必要的资源\u003C\u002Fh3>\u003Cp>数据提取不需要图像,CSS,字体,和媒体文件. 截断它们会加快页面载荷 :\u003C\u002Fp>\u003Cpre>\u003Ccode># Playwright resource blocking\nasync def fast_scrape(page, url):\n    # Block images, CSS, fonts, media\n    await page.route(\"**\u002F*.{png,jpg,jpeg,gif,svg,css,woff,woff2,mp4,webm}\",\n                     lambda route: route.abort())\n    # Also block tracking scripts\n    await page.route(\"**\u002F*google-analytics*\", lambda route: route.abort())\n    await page.route(\"**\u002F*facebook*\", lambda route: route.abort())\n    await page.goto(url, wait_until=\"domcontentloaded\")  # Faster than networkidle\n    return await page.content()\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>2. 使用 \" 权利等待战略 \"\u003C\u002Fh3>\u003Ctable>\n\u003Ccaption>2. 使用 &quot; 权利等待战略 &quot;\u003C\u002Fcaption>\u003Cthead>\u003Ctr>\u003Cth>战略\u003C\u002Fth>\u003Cth>速度\u003C\u002Fth>\u003Cth>可靠性\u003C\u002Fth>\u003Cth>使用大小写\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>\u003Ccode>domcontentloaded\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>快点\u003C\u002Ftd>\u003Ctd>可能丢失同步数据\u003C\u002Ftd>\u003Ctd>有内含数据的页面\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>\u003Ccode>load\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>中型\u003C\u002Ftd>\u003Ctd>不错\u003C\u002Ftd>\u003Ctd>多数页\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>\u003Ccode>networkidle\u003C\u002Fcode>\u003C\u002Ftd>\u003Ctd>慢点\u003C\u002Ftd>\u003Ctd>最高\u003C\u002Ftd>\u003Ctd>重型SPA, 无限滚动\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>特定选择器\u003C\u002Ftd>\u003Ctd>变量\u003C\u002Ftd>\u003Ctd>最高\u003C\u002Ftd>\u003Ctd>当你知道目标元素\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch3>3. 重新使用浏览器\u003C\u002Fh3>\u003Cp>推出浏览器需要1-3秒. 对于批量刮刮,一次发射,并为每个URL创建新的页面\u002F文本:\u003C\u002Fp>\u003Cpre>\u003Ccode>from playwright.sync_api import sync_playwright\nclass BrowserPool:\n    \"\"\"Reusable browser pool for efficient headless scraping.\"\"\"\n    def __init__(self, pool_size: int = 3):\n        self.pool_size = pool_size\n        self.playwright = None\n        self.browsers = []\n    def start(self):\n        self.playwright = sync_playwright().start()\n        for _ in range(self.pool_size):\n            browser = self.playwright.chromium.launch(\n                headless=True,\n                proxy={\n                    \"server\": \"http:\u002F\u002Fgate.proxyhat.com:8080\",\n                    \"username\": \"USERNAME\",\n                    \"password\": \"PASSWORD\",\n                }\n            )\n            self.browsers.append(browser)\n    def get_browser(self, index: int):\n        return self.browsers[index % self.pool_size]\n    def stop(self):\n        for browser in self.browsers:\n            browser.close()\n        self.playwright.stop()\n# Usage\npool = BrowserPool(pool_size=3)\npool.start()\nfor i, url in enumerate(urls):\n    browser = pool.get_browser(i)\n    context = browser.new_context()\n    page = context.new_page()\n    page.goto(url, wait_until=\"networkidle\")\n    html = page.content()\n    context.close()\npool.stop()\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>4. 截取API 调用而非解析 DOM\u003C\u002Fh3>\u003Cp>许多SPA从API获取数据. 截取这些 API 直接调用—— 您可以在不解析 HTML 的情况下获得干净的 JSON :\u003C\u002Fp>\u003Cpre>\u003Ccode>const puppeteer = require('puppeteer');\nasync function interceptAPIData(url) {\n  const browser = await puppeteer.launch({\n    headless: 'new',\n    args: ['--proxy-server=http:\u002F\u002Fgate.proxyhat.com:8080'],\n  });\n  const page = await browser.newPage();\n  await page.authenticate({ username: 'USERNAME', password: 'PASSWORD' });\n  const apiResponses = [];\n  \u002F\u002F Intercept XHR\u002Ffetch responses\n  page.on('response', async (response) => {\n    const url = response.url();\n    if (url.includes('\u002Fapi\u002F') || url.includes('\u002Fgraphql')) {\n      try {\n        const json = await response.json();\n        apiResponses.push({ url, data: json });\n      } catch {\n        \u002F\u002F Not JSON, skip\n      }\n    }\n  });\n  await page.goto(url, { waitUntil: 'networkidle2' });\n  await browser.close();\n  return apiResponses;\n}\n\u002F\u002F Get clean API data instead of scraping DOM\nconst data = await interceptAPIData('https:\u002F\u002Fexample.com\u002Fproducts');\nconsole.log(`Intercepted ${data.length} API calls`);\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>无头浏览器与 HTTP 比较\u003C\u002Fh2>\u003Ctable>\n\u003Ccaption>无头浏览器与 HTTP 比较\u003C\u002Fcaption>\u003Cthead>\u003Ctr>\u003Cth>度量衡\u003C\u002Fth>\u003Cth>简单的 HTTP + 代理\u003C\u002Fth>\u003Cth>无头浏览器 + 代理\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>每页速度\u003C\u002Ftd>\u003Ctd>0.5-2秒\u003C\u002Ftd>\u003Ctd>3-15秒\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>每个实例的内存\u003C\u002Ftd>\u003Ctd>~50 MB 键\u003C\u002Ftd>\u003Ctd>200-500甲基溴\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>CPU 使用情况\u003C\u002Ftd>\u003Ctd>最小数\u003C\u002Ftd>\u003Ctd>重大\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>每页带宽\u003C\u002Ftd>\u003Ctd>50-200 KB (韩语)\u003C\u002Ftd>\u003Ctd>2-10 MB(有资源)\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Java 脚本渲染\u003C\u002Ftd>\u003Ctd>没有\u003C\u002Ftd>\u003Ctd>满\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>反机器人绕行\u003C\u002Ftd>\u003Ctd>有限\u003C\u002Ftd>\u003Ctd>更好的( 真实浏览器)\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>同时页\u003C\u002Ftd>\u003Ctd>100岁以上\u003C\u002Ftd>\u003Ctd>每台3-10台\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch2>最佳做法\u003C\u002Fh2>\u003Cul>\u003Cli>\u003Cstrong>总是先尝试HTTP.\u003C\u002Fstrong> 在使用无头浏览器之前,先检查API的端点,服务器上的内容,或者JSON嵌入到HTML中.\u003C\u002Fli>\u003Cli>\u003Cstrong>封锁不必要的资源。\u003C\u002Fstrong> 图像,CSS,和字体在不提供数据的情况下加载时间.\u003C\u002Fli>\u003Cli>\u003Cstrong>使用特定的选择器等待 。\u003C\u002Fstrong> \u003Ccode>networkidle\u003C\u002Fcode> 安全但缓慢。 等待您需要的特定元素 。\u003C\u002Fli>\u003Cli>\u003Cstrong>重用浏览器实例 。\u003C\u002Fstrong> 发射一次,每页创建新的上下文.\u003C\u002Fli>\u003Cli>拦截API呼叫. 许多SPA通过API加载数据——直接拦截JSON.\u003C\u002Fli>\u003Cli>限制货币。 无头浏览器是内存密集型的. 每GB的RAM共3-5页是一个很好的规则.\u003C\u002Fli>\u003Cli>使用住宅代理. \u003Ca href=\"\u002Fcn\u002Fpricing\">代理哈特住宅代理\u003C\u002Fa> 提供最高的信任分数,减少运行无头浏览器时的检测.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>对于无头浏览器遇到的处理 CAPTCHA ,请参见 \u003Ca href=\"\u002Fcn\u002Fblog\u002Fcaiji-zhong-chuli-captcha\">处理CAPTCHA 当摇摆\u003C\u002Fa>缩放无头浏览器 \u003Ca href=\"\u002Fcn\u002Fblog\u002Fkuozhan-caiji-jiagou\">如何缩放基础设施\u003C\u002Fa>。 。 。\u003C\u002Fp>\u003Cp>开始吧 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FProxyHatCom\u002Fpython-sdk\" rel=\"noopener noreferrer\">Python SDK 键盘\u003C\u002Fa>, (中文). \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FProxyHatCom\u002Fnode-sdk\" rel=\"noopener noreferrer\">节点 SDK\u003C\u002Fa>,或 \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FProxyHatCom\u002Fgo-sdk\" rel=\"noopener noreferrer\">冲啊 SDK\u003C\u002Fa> 用于代理集成,并探索 \u003Ca href=\"\u002Fcn\u002Fuse-cases\u002Fweb-scraping\">网页搜索的代理用户名\u003C\u002Fa>。 。 。\u003C\u002Fp>","如何爬取JavaScript重度渲染网站","爬取JavaScript重度渲染网站的完整指南。学习无头浏览器使用、API端点发现、SPA页面爬取策略和性能优化技术，高效采集动态内容。","\u002Fcn\u002Fblog\u002Fcaiji-javascript-zhongdu-wangzhan",null,"https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fcaiji-javascript-zhongdu-wangzhan-og.webp",[17,20,23,26,29,32,35,38,41],{"question":18,"answer":19},"为什么传统爬虫无法处理JavaScript渲染的网站？","传统爬虫（如Python requests、curl）只获取服务器返回的原始HTML。现代网站使用React、Vue、Angular等框架，页面内容由JavaScript在客户端动态渲染。原始HTML可能只包含一个空的div容器和一堆JS文件，没有实际数据内容。",{"question":21,"answer":22},"爬取JS渲染网站有哪些方法？","三种主要方法：1）使用无头浏览器（Puppeteer\u002FPlaywright）渲染页面后提取内容——最可靠但资源消耗大；2）拦截浏览器网络请求，找到返回数据的API端点，直接请求API——最高效；3）使用预渲染服务（如Prerender.io）获取渲染后的HTML——介于两者之间。",{"question":24,"answer":25},"如何发现网站使用的API端点？","打开浏览器开发者工具的Network标签页，加载目标页面并观察XHR\u002FFetch请求。找到返回JSON数据的API调用。分析请求的URL模式、参数和认证方式。然后直接通过代理请求这些API端点获取结构化数据，无需渲染整个页面，效率大幅提升。",{"question":27,"answer":28},"无头浏览器配合代理爬取JS网站的资源消耗如何？","每个无头浏览器实例（Chromium）约消耗100-300MB内存。同时运行10个实例需要1-3GB内存。CPU使用也显著高于简单HTTP请求。优化策略：限制并发实例数、禁用不必要的资源加载（图片、字体）、复用浏览器上下文、定期重启实例防止内存泄漏。",{"question":30,"answer":31},"如何等待JS渲染完成？","避免使用固定等待时间（如sleep 5秒）——既浪费时间又不可靠。使用智能等待策略：等待特定DOM元素出现（page.waitForSelector）、等待网络活动停止（page.waitForLoadState(\"networkidle\")）、等待特定API响应完成。设置合理的超时限制（通常30秒）防止无限等待。",{"question":33,"answer":34},"我总是需要JavaScript网站的无头浏览器吗?","没有 许多JavaScript-havy站点从API端点加载数据. 请检查access-date=中的日期值 (帮助) XHR\u002Ffach请求的浏览器的网络标签——如果数据来自API,可以通过一个代理程序直接使用简单的HTTP请求调用API,这要快得多.",{"question":36,"answer":37},"Puppeteer或Playwright——哪一种更适合刮?","Playwright一般被推荐用于新项目. 它支持多个浏览器引擎(Chrimium,Firefox,WebKit),在Python中拥有更好的自动等待,本地的ASync支持,以及内置代理配置. 普普特尔更成熟,如果处于节点世界,拥有更大的生态系统.",{"question":39,"answer":40},"我能同时运行多少个无头浏览器页面?","每页消耗RAM的200-500 MB. 在一台拥有8GB内存的机器上,3-10页并存是现实的. 使用资源屏蔽(images, CSS)来减少内存. 对于更高的货币,使用基于队列的架构在多个机器之间分布.",{"question":42,"answer":43},"为什么使用无头浏览器的代理?","即使有了真正的浏览器,同一IP的重复请求也会被封杀. 代理旋转您的IP, 所以每个页面负荷似乎来自不同的用户 。 通过代理Hat(英语:ProxyHat)的居家代理提供最高的信任分数,最小化块和CAPTCHA.",[45,46,47,48,49],"现代网站依赖JavaScript渲染内容，通常需要使用无头浏览器（如Puppeteer或Playwright）结合代理来爬取动态数据。","在使用无头浏览器前，应先检查网站是否有API端点或服务器端渲染，直接调用API获取JSON更快且成本更低。","优化无头浏览器性能的关键是拦截并屏蔽图片、CSS等不必要的资源，并使用特定选择器等待而非networkidle。","批量爬取时应重用浏览器实例，为每个URL创建新页面，并限制并发数（每GB内存约3-5页）以节省内存。","许多单页应用通过API加载数据，可直接拦截XHR\u002Ffetch响应获取干净的JSON，无需解析DOM。",false,"2026-02-21T10:07:49+00:00","2026-07-19T03:13:07+00:00","2026-02-26T00:33:22+00:00","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fcaiji-javascript-zhongdu-wangzhan-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fcaiji-javascript-zhongdu-wangzhan-card.webp",10,{"name":58,"slug":59,"bio":60,"avatar_url":14,"website_url":14,"social_links":14},"ProxyHat Team","proxyhat-team","The ProxyHat editorial team covers proxies, web scraping, and data extraction.",[62],{"id":63,"slug":64,"name":65,"description":14,"meta_title":66,"meta_description":67,"parent_id":14},1,"web-scraping","网页抓取","网页抓取指南 | ProxyHat 博客","网页抓取技术、代理策略和数据提取最佳实践。",[69,70],{"id":63,"slug":64,"name":65},{"id":71,"slug":72,"name":73},21,"headless-browser","无头浏览器",{"ja":75,"fr":76,"ru":77,"pl":78,"de":79,"tr":80,"zh":13,"it":81,"en":82,"es":83,"ko":84,"pt":85,"x-default":82},"\u002Fja\u002Fblog\u002Fjavascript-takai-web-saito-no-sukureipingu","\u002Ffr\u002Fblog\u002Fscraper-les-sites-web-javascript-heavy","\u002Fru\u002Fblog\u002Fskraping-saytov-s-javascript","\u002Fpl\u002Fblog\u002Fjak-scrape-javascript-ciezkie-strony-internetowe","\u002Fde\u002Fblog\u002Fjavascript-lastige-websites-scrapen","\u002Ftr\u002Fblog\u002Fjavascript-agirlikli-siteleri-scraping","\u002Fit\u002Fblog\u002Fcome-scrape-javascript-heavy-siti-web","\u002Fblog\u002Fscrape-javascript-heavy-websites","\u002Fes\u002Fblog\u002Fscrapear-sitios-web-con-mucho-javascript","\u002Fko\u002Fblog\u002Fjavascript-heavy-website-scraping","\u002Fpt\u002Fblog\u002Fcomo-fazer-scraping-sites-pesados-em-javascript",{"ja":75,"fr":76,"ru":77,"pl":78,"de":79,"tr":80,"zh":13,"it":81,"en":82,"es":83,"ko":84,"pt":85},286,[89,126,151,184],{"id":90,"slug":91,"title":92,"excerpt":93,"featured_image_url":94,"featured_image_alt":95,"card_image_url":96,"og_image_url":97,"published_at":98,"updated_at":99,"content_updated_at":100,"reading_time_minutes":101,"is_featured":50,"indexable":4,"views":102,"author":103,"categories":104,"tags":111},206,"camoufox-zhuzhai-daili-python-zhinan","Camoufox 搭配住宅代理：代码优先的 Python 指南","如何让在 C++ 层打补丁的 Firefox——Camoufox 在住宅代理后运行：当前的 Python API、geoip 为什么需要粘性会话、指纹一致性检查清单，以及何时 Patchright 或 nodriver 更合适。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-master.webp","Camoufox with Residential Proxies: A Code-First Python Guide","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fcamoufox-zhuzhai-daili-python-zhinan-og.webp","2026-10-13T09:00:00+00:00","2026-10-13T09:00:22+00:00","2026-10-03T09:41:40+00:00",14,48,{"name":58,"slug":59,"bio":60,"avatar_url":14,"website_url":14,"social_links":14},[105],{"id":106,"slug":107,"name":108,"description":14,"meta_title":109,"meta_description":110,"parent_id":14},4,"kaifa-zhinan","开发者指南","开发者指南 | ProxyHat 博客","代码教程和SDK指南，帮助您将代理集成到应用程序中。",[112,113,117,118,122],{"id":63,"slug":64,"name":65},{"id":114,"slug":115,"name":116},6,"anti-detection","反检测",{"id":71,"slug":72,"name":73},{"id":119,"slug":120,"name":121},9,"python","Python",{"id":123,"slug":124,"name":125},2,"residential-proxies","住宅代理",{"id":127,"slug":128,"title":129,"excerpt":130,"featured_image_url":131,"featured_image_alt":14,"card_image_url":132,"og_image_url":133,"published_at":134,"updated_at":52,"content_updated_at":135,"reading_time_minutes":56,"is_featured":50,"indexable":50,"views":136,"author":137,"categories":138,"tags":144},39,"wutou-liulanqi-daili-shezhi","无头浏览器 + 代理：Puppeteer和Playwright完整设置指南","一步步指南,用于配置Puppeteer和Playwright的代理旋转,隐形插件,设备仿真,以及使用住宅代理同时刮刮模式.","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fwutou-liulanqi-daili-shezhi-master.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fwutou-liulanqi-daili-shezhi-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog\u002Fwutou-liulanqi-daili-shezhi-og.webp","2026-02-12T15:02:24+00:00","2026-10-03T08:21:31+00:00",228,{"name":58,"slug":59,"bio":60,"avatar_url":14,"website_url":14,"social_links":14},[139],{"id":114,"slug":140,"name":141,"description":14,"meta_title":142,"meta_description":143,"parent_id":14},"fan-jiqiren","反机器人与安全","反机器人与安全指南 | ProxyHat 博客","反机器人系统技术分析、检测规避和代理安全。",[145,149,150],{"id":146,"slug":147,"name":148},16,"anti-bot","反机器人",{"id":71,"slug":72,"name":73},{"id":63,"slug":64,"name":65},{"id":152,"slug":153,"title":154,"excerpt":155,"featured_image_url":156,"featured_image_alt":157,"card_image_url":158,"og_image_url":159,"published_at":160,"updated_at":161,"content_updated_at":100,"reading_time_minutes":146,"is_featured":50,"indexable":4,"views":162,"author":163,"categories":164,"tags":171},215,"tiktok-shop-shangpin-shuju-caiji","采集 TikTok Shop 商品数据用于市场调研","官方渠道优先：TikTok Shop Partner API 和 Research API 实际开放了哪些数据，什么时候授权数据更划算，以及如何在正确的市场里慢速读取公开商品页。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Ftiktok-shop-shangpin-shuju-caiji-master.webp","Collecting TikTok Shop Product Data for Market Research","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Ftiktok-shop-shangpin-shuju-caiji-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Ftiktok-shop-shangpin-shuju-caiji-og.webp","2026-10-29T09:00:00+00:00","2026-10-29T09:00:19+00:00",58,{"name":58,"slug":59,"bio":60,"avatar_url":14,"website_url":14,"social_links":14},[165],{"id":166,"slug":167,"name":168,"description":14,"meta_title":169,"meta_description":170,"parent_id":14},5,"dianshang","电商与竞争情报","电商数据抓取指南 | ProxyHat 博客","电商数据抓取、价格监控和竞争情报指南。",[172,175,176,180],{"id":101,"slug":173,"name":174},"ecommerce","电商",{"id":63,"slug":64,"name":65},{"id":177,"slug":178,"name":179},15,"price-monitoring","价格监控",{"id":181,"slug":182,"name":183},18,"geo-targeting","地理定位",{"id":185,"slug":186,"title":187,"excerpt":188,"featured_image_url":189,"featured_image_alt":190,"card_image_url":191,"og_image_url":192,"published_at":193,"updated_at":194,"content_updated_at":100,"reading_time_minutes":101,"is_featured":50,"indexable":4,"views":127,"author":195,"categories":196,"tags":198},210,"ai-agent-daili-peizhi","AI Agent 代理配置：browser-use、Crawl4AI、MCP","运行在云服务器上的智能体从数据中心 IP 出口。本文给出 browser-use、Crawl4AI 和 MCP 服务器当前可用的代理配置，附粘性与轮换的决策表，以及需要避开的成本陷阱。","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-master.webp","Proxy Setup for AI Agents: browser-use, Crawl4AI and an MCP Server","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-card.webp","https:\u002F\u002Fstatic.proxyhat.com\u002Fstorage\u002Fblog-covers\u002Fzh\u002Fai-agent-daili-peizhi-og.webp","2026-10-24T09:00:00+00:00","2026-10-24T09:00:20+00:00",{"name":58,"slug":59,"bio":60,"avatar_url":14,"website_url":14,"social_links":14},[197],{"id":106,"slug":107,"name":108,"description":14,"meta_title":109,"meta_description":110,"parent_id":14},[199,200,201,202],{"id":63,"slug":64,"name":65},{"id":123,"slug":124,"name":125},{"id":119,"slug":120,"name":121},{"id":203,"slug":204,"name":205},22,"playwright","Playwright",[]]