{"id":28841,"date":"2025-04-20T03:31:22","date_gmt":"2025-04-19T19:31:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/28841.html"},"modified":"2025-04-20T03:31:22","modified_gmt":"2025-04-19T19:31:22","slug":"python-pyppeteer-%e4%b8%8eplaywright-%e6%a8%a1%e6%8b%9f%e6%b5%8f%e8%a7%88%e5%99%a8%e8%af%b7%e6%b1%82-%e9%83%a8%e7%bd%b2%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%81%87%e5%88%b0%e7%9a%84%e5%9d%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/28841.html","title":{"rendered":"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751"},"content":{"rendered":"<p>\u5728\u670d\u52a1\u5668\u90e8\u7f72\u9047\u5230\u7684\u95ee\u9898<\/p>\n<p>\u5728\u670d\u52a1\u5668\u4e0a\u90e8\u7f72\u540e\u5982\u679c\u9047\u5230\u4ee3\u7801\u6267\u884c\u5361\u4e3b\u95ee\u9898 \u901a\u8fc7debug \u663e\u793a \u4ee3\u7801\u5230 browser &#061; await launch(headless&#061;False)\u5361\u4e3b\u4e86 ,\u7531\u4e8e\u670d\u52a1\u5668\u6ca1\u6709\u6d4f\u89c8\u5668\u7684\u56fe\u5f62\u5316\u73af\u5883,\u6240\u4ee5\u53ea\u80fd\u5c06\u4fee\u6539\u4e3a\u65e0\u5934\u6d4f\u89c8\u5668\u7684\u6a21\u5f0f\u542f\u52a8 browser &#061; await launch(headless&#061;True)<\/p>\n<p>async def crawling_html(language, redis):<br \/>\n    # \u542f\u52a8\u6d4f\u89c8\u5668<br \/>\n    browser &#061; await launch(headless&#061;True)<br \/>\n    try:<br \/>\n        logger.info(f&#034;Crawling HTML for language {language}&#8230;&#034;)<br \/>\n        page &#061; await browser.newPage()<br \/>\n        # \u8bbe\u7f6e\u6d4f\u89c8\u5668\u7684\u8bed\u8a00<br \/>\n        await page.setExtraHTTPHeaders({<br \/>\n            &#039;Accept-Language&#039;: language<br \/>\n        })<br \/>\n        # \u6253\u5f00 WhatsApp Web<br \/>\n        await page.goto(&#039;https:\/\/web.whatsapp.com\/&#039;)<br \/>\n        await page.setViewport({&#039;width&#039;: 1920, &#039;height&#039;: 960})<br \/>\n        # \u83b7\u53d6\u9875\u9762\u7684 HTML \u5185\u5bb9<br \/>\n        html &#061; await page.content()<br \/>\n    except Exception as e:<br \/>\n        logger.exception(e)<br \/>\n    finally:<br \/>\n        await browser.close()<\/p>\n<p>\u4f7f\u7528\u4e86\u65e0\u5934\u6d4f\u89c8\u5668\u7684\u6a21\u5f0f \u7a0b\u5e8f\u53ef\u4ee5\u8fd0\u884c\u4e0b\u53bb ,\u4f46\u662f\u5728\u6267\u884c\u5230 await page.goto(&#039;https:\/\/web.whatsapp.com\/&#039;) \u65f6\u5019\u51fa\u73b0\u95ee\u9898 \u7531\u4e8e\u4f7f\u7528\u4e86\u65e0\u5934\u6d4f\u89c8\u5668\u6a21\u5f0f \u53ef\u80fd\u88ab\u68c0\u6d4b\u5230\u4e86\u662f\u81ea\u52a8\u5316\u5de5\u5177\u8bbf\u95ee, \u8bbf\u95ee\u8d85\u65f6\u4e0d\u54cd\u5e94 , \u7136\u540e\u901a\u8fc7\u4fee\u6539 User-Agent&#xff0c;\u8ba9 Pyppeteer \u6a21\u62df\u6210\u771f\u5b9e\u6d4f\u89c8\u5668&#xff0c;\u907f\u514d\u88ab\u7f51\u7ad9\u68c0\u6d4b\u5230\u4f7f\u7528\u81ea\u52a8\u5316\u5de5\u5177<\/p>\n<p>\u7531\u4e8e\u4e00\u5f00\u59cb\u4f7f\u7528\u7684User-Agent\u53c2\u6570\u4e0e\u5b9e\u9645\u7684\u53c2\u6570\u8bbe\u7f6e\u6709\u5dee\u5f02 ,\u6240\u4ee5\u8bf7\u6c42\u867d\u7136\u6ca1\u6709\u5361\u4f4f \u4f46\u662f\u8bf7\u6c42\u62ff\u5230\u7684\u7ed3\u679c\u9875\u9762\u4e0d\u662f\u6b63\u5e38\u7684\u9875\u9762,\u63d0\u793a\u51fa\u73b0\u4e86\u9519\u8bef,\u6216\u8005\u62ff\u5230\u7684\u9875\u9762\u65f6\u63d0\u793a\u6d4f\u89c8\u5668\u7248\u672c\u8fc7\u4f4e,\u6216\u8005\u4e00\u76f4\u5728\u52a0\u8f7d\u51fa\u4e0d\u6765\u9875\u9762,\u4e71\u7801,\u603b\u4e4b\u4e0d\u80fd\u6b63\u786e\u5730\u5904\u7406\u3002<\/p>\n<p>\u5206\u6790\u662f\u88ab\u68c0\u6d4b\u5230\u4e3a\u5f02\u5e38\u8bbf\u95ee,\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u670d\u52a1\u5668\u5b89\u88c5\u7684\u8def\u5f84 \u67e5\u5230\u5b89\u88c5\u8def\u5f84\u540e \u914d\u7f6e\u4e0a\u542f\u52a8\u6d4f\u89c8\u5668\u7684\u8def\u5f84,\u5e76\u4e14\u67e5\u770b\u5f53\u524d\u6d4f\u89c8\u5668\u7248\u672cgoogle-chrome &#8211;version ,\u914d\u7f6e\u6b63\u786e\u7684 User-Agent\u9632\u6b62\u88ab\u68c0\u6d4b\u5230\u4e3a\u81ea\u52a8\u5316\u8bbf\u95ee<\/p>\n<p>\u624b\u52a8\u914d\u7f6e\u6d4f\u89c8\u5668\u7684\u4f4d\u7f6e<\/p>\n<p>browser &#061; await launch({<br \/>\n    &#039;headless&#039;: True,<br \/>\n    &#039;executablePath&#039;: &#039;\/path\/to\/your\/chrome&#039;  # \u66ff\u6362\u4e3a\u4f60\u672c\u5730 Chrome \u6216 Chromium \u7684\u5b89\u88c5\u8def\u5f84<br \/>\n}) <\/p>\n<h4>\u6c99\u76d2\u6a21\u5f0f \u89e3\u51b3\u53ef\u80fd\u5bfc\u81f4\u5361\u4e3b\u95ee\u9898 \u53ef\u80fd\u6709\u4e9b\u6743\u9650\u4e0d\u8db3\u95ee\u9898<\/h4>\n<h5>\u4e3a\u4ec0\u4e48\u5728\u670d\u52a1\u5668\u4e0a\u8981\u7981\u7528\u6c99\u76d2\u6a21\u5f0f&#xff1f;<\/h5>\n<p>\u5728\u670d\u52a1\u5668\u73af\u5883\u4e2d&#xff0c;\u542f\u7528\u6c99\u76d2\u6a21\u5f0f\u6709\u65f6\u4f1a\u5bfc\u81f4\u6743\u9650\u6216\u6027\u80fd\u95ee\u9898&#xff0c;\u56e0\u6b64\u7981\u7528\u6c99\u76d2\u6a21\u5f0f\u53ef\u4ee5\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<h5>\u6743\u9650\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u65e0\u5934\u6d4f\u89c8\u5668\u5728\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u65f6\u53ef\u80fd\u9047\u5230\u6743\u9650\u4e0d\u8db3\u7684\u95ee\u9898\u3002\u5728\u67d0\u4e9b\u73af\u5883\u4e2d&#xff0c;\u7279\u522b\u662f Docker \u5bb9\u5668\u3001\u865a\u62df\u673a\u6216\u65e0\u7279\u6743\u7684 Linux \u73af\u5883\u4e2d&#xff0c;\u6c99\u76d2\u6a21\u5f0f\u53ef\u80fd\u4f1a\u56e0\u4e3a\u6743\u9650\u95ee\u9898\u800c\u5bfc\u81f4 Chromium \u6216 Chrome \u65e0\u6cd5\u6b63\u5e38\u542f\u52a8\u3002<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3\u6743\u9650\u51b2\u7a81&#xff1a;\u6c99\u76d2\u6a21\u5f0f\u8981\u6c42\u6d4f\u89c8\u5668\u8fdb\u7a0b\u6709\u4e00\u5b9a\u7684\u6743\u9650&#xff08;\u4f8b\u5982\u80fd\u591f\u4fee\u6539\u8fdb\u7a0b\u7684\u7528\u6237 ID&#xff09;&#xff0c;\u5728\u4e00\u4e9b\u53d7\u9650\u73af\u5883&#xff08;\u5982 Docker&#xff09;\u4e2d\u65e0\u6cd5\u63d0\u4f9b\u8fd9\u4e9b\u6743\u9650\u3002\u56e0\u6b64&#xff0c;\u7981\u7528\u6c99\u76d2\u53ef\u4ee5\u7ed5\u8fc7\u8fd9\u4e9b\u6743\u9650\u95ee\u9898\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>\u6027\u80fd\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u5728\u67d0\u4e9b\u573a\u666f\u4e0b&#xff0c;\u6c99\u76d2\u6a21\u5f0f\u53ef\u80fd\u4f1a\u589e\u52a0\u7cfb\u7edf\u7684\u8d1f\u8f7d\u6216\u964d\u4f4e\u6027\u80fd&#xff0c;\u5c24\u5176\u662f\u5728\u8d44\u6e90\u6709\u9650\u7684\u670d\u52a1\u5668\u6216\u865a\u62df\u73af\u5883\u4e2d\u3002\u7981\u7528\u6c99\u76d2\u6a21\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd&#xff0c;\u51cf\u5c11\u7cfb\u7edf\u5f00\u9500\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>\u907f\u514d\u6d4f\u89c8\u5668\u5d29\u6e83<\/h5>\n<ul>\n<li>\n<p>\u5728\u67d0\u4e9b\u73af\u5883\u4e2d&#xff0c;\u542f\u7528\u6c99\u76d2\u6a21\u5f0f\u53ef\u80fd\u5bfc\u81f4\u6d4f\u89c8\u5668\u5d29\u6e83\u6216\u5361\u6b7b\u3002\u7981\u7528\u6c99\u76d2\u6a21\u5f0f\u53ef\u4ee5\u907f\u514d\u6d4f\u89c8\u5668\u56e0\u4e3a\u6c99\u76d2\u9650\u5236\u800c\u542f\u52a8\u5931\u8d25\u6216\u5d29\u6e83\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>\u4ec0\u4e48\u65f6\u5019\u7981\u7528\u6c99\u76d2\u6a21\u5f0f&#xff1f;<\/h4>\n<ul>\n<li>\n<p>\u5728\u65e0\u56fe\u5f62\u754c\u9762\u7684\u670d\u52a1\u5668\u3001Docker \u5bb9\u5668\u3001\u865a\u62df\u673a\u3001CI\/CD \u7cfb\u7edf\u4e2d&#xff0c;\u5e38\u5e38\u9700\u8981\u7981\u7528\u6c99\u76d2\u6a21\u5f0f&#xff0c;\u5c24\u5176\u662f\u5f53\u4f60\u8fd0\u884c\u65e0\u5934\u6d4f\u89c8\u5668\u65f6&#xff08;\u5982\u4f7f\u7528 headless: true \u6a21\u5f0f\u7684 Pyppeteer\u3001Playwright \u6216 Selenium&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u5f00\u53d1\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u6216\u722c\u866b\u4e2d&#xff0c;\u5982\u679c\u9047\u5230\u6d4f\u89c8\u5668\u542f\u52a8\u5931\u8d25\u3001\u6743\u9650\u4e0d\u8db3\u7b49\u95ee\u9898&#xff0c;\u7981\u7528\u6c99\u76d2\u6a21\u5f0f\u53ef\u80fd\u662f\u89e3\u51b3\u65b9\u6848\u4e4b\u4e00\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7981\u7528\u6c99\u76d2\u6a21\u5f0f\u793a\u4f8b\u4ee3\u7801:<\/p>\n<h5>1. Pyppeteer<\/h5>\n<p>browser &#061; await launch({<br \/>\n    &#039;headless&#039;: True,<br \/>\n    &#039;args&#039;: [&#039;&#8211;no-sandbox&#039;, &#039;&#8211;disable-setuid-sandbox&#039;]<br \/>\n})<\/p>\n<h5>2. Playwright<\/h5>\n<p>async with async_playwright() as p:<br \/>\n    browser &#061; await p.chromium.launch(<br \/>\n        headless&#061;True,<br \/>\n        args&#061;[&#039;&#8211;no-sandbox&#039;, &#039;&#8211;disable-setuid-sandbox&#039;]<br \/>\n    ) <\/p>\n<p>\u6240\u4ee5&#xff0c;\u6700\u7ec8\u4ee3\u7801:<\/p>\n<p>async def crawling_html(language, redis):<br \/>\n    logger.info(f&#039;Start crawling HTML for language {language}&#8230;&#039;)<br \/>\n    is_prod &#061; os.getenv(&#039;PROJECT_ENV&#039;) &#061;&#061; &#039;prod&#039;<br \/>\n    logger.info(f&#039;is_prod: {is_prod}&#039;)<br \/>\n    # \u542f\u52a8\u6d4f\u89c8\u5668<br \/>\n    browser &#061; await launch({<br \/>\n        &#039;headless&#039;: True,  # \u65e0\u5934\u6a21\u5f0f&#xff0c;\u4e0d\u9700\u8981\u663e\u793a\u754c\u9762<br \/>\n        &#039;executablePath&#039;: &#039;\/usr\/bin\/google-chrome&#039; if is_prod else &#039;C:\/Program Files\/Google\/Chrome\/Application\/chrome.exe&#039;, # \u914d\u7f6e\u6d4f\u89c8\u5668\u4f4d\u7f6e\u4e0d\u9002\u7528\u9ed8\u8ba4\u5b89\u88c5\u7684\u6d4f\u89c8\u5668\u9632\u6b62\u5b89\u88c5\u95ee\u9898<br \/>\n        &#039;args&#039;: [&#039;&#8211;no-sandbox&#039;, &#039;&#8211;disable-setuid-sandbox&#039;, &#039;&#8211;disable-features&#061;IsolateOrigins,site-per-process&#039;]<br \/>\n        # \u7981\u7528\u6c99\u76d2\u6a21\u5f0f&#xff0c;\u907f\u514d\u6743\u9650\u95ee\u9898<br \/>\n    })<br \/>\n    version_info &#061; await browser.version()<br \/>\n    try:<br \/>\n        page &#061; await browser.newPage()<br \/>\n        #\u5220\u9664\u4e4b\u524d\u7684\u7f13\u5b58<br \/>\n        await page.deleteCookie(*await page.cookies())<br \/>\n        #\u6a21\u62df\u7528\u6237\u54cd\u5e94<br \/>\n        await page.mouse.move(100, 100)<br \/>\n        await page.mouse.click(100, 100)<br \/>\n        # \u6253\u5f00 WhatsApp Web&#xff0c;\u5e76\u7b49\u5f85\u9875\u9762\u52a0\u8f7d\u5b8c\u6210<br \/>\n        await page.setExtraHTTPHeaders({&#039;Accept-Language&#039;: language})<br \/>\n        #\u6a21\u62dfUserAgent<br \/>\n        await page.setUserAgent(<br \/>\n            &#034;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/92.0.4515.107 Safari\/537.36&#034;)<br \/>\n        #\u914d\u7f6e\u8d85\u65f6\u65f6\u95f4<br \/>\n        await page.goto(&#039;https:\/\/web.whatsapp.com\/&#039;, timeout&#061;120000)<br \/>\n        await page.setViewport({&#039;width&#039;: 1920, &#039;height&#039;: 960})<br \/>\n        # \u83b7\u53d6\u9875\u9762\u7684 HTML \u5185\u5bb9<br \/>\n        html &#061; await page.content()<br \/>\n        # \u4ecehtml\u4e2d\u89e3\u6790\u51fa\u7248\u672c\u53f7<br \/>\n        version &#061; &#039;&#039;<br \/>\n        $&#8230;\u4e00\u4e9b\u5176\u4ed6\u7684\u64cd\u4f5c&#8230;<br \/>\n    except Exception as e:<br \/>\n        logger.exception(e)<br \/>\n    finally:<br \/>\n        await browser.close() <\/p>\n<h5>\u53e6\u5916\u4e00\u79cd\u53ef\u80fd\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6848 Xvfb&#xff08;\u865a\u62df\u663e\u793a&#xff09; \u4e0d\u63a8\u8350 \u8017\u8d39\u8d44\u6e90 \u65e0\u5934\u6a21\u5f0f\u540e\u53f0\u8fd0\u884c\u66f4\u9ad8\u6548 \u672a\u91c7\u7528<\/h5>\n<p>\u5982\u679c\u4f60\u9700\u8981 headless&#061;False \u4f46\u670d\u52a1\u5668\u6ca1\u6709\u663e\u793a\u73af\u5883&#xff0c;\u4f60\u53ef\u4ee5\u4f7f\u7528 Xvfb&#xff08;\u865a\u62df\u663e\u793a\u5e27\u7f13\u51b2&#xff09;\u6a21\u62df\u56fe\u5f62\u73af\u5883\u3002\u5b89\u88c5\u548c\u4f7f\u7528 Xvfb&#xff1a;<\/p>\n<li>\n<p>\u5b89\u88c5 Xvfb&#xff1a;<\/p>\n<\/li>\n<p>sudo apt-get install -y xvfb<\/p>\n<li>\n<p>\u5728 Xvfb \u4e2d\u8fd0\u884c\u4f60\u7684\u811a\u672c&#xff1a;<\/p>\n<\/li>\n<p>xvfb-run python your_script.py <\/p>\n<p>\u6a21\u62df\u6d4f\u89c8\u5668\u7684\u8bf7\u6c42\u6846\u67b6pyppeteer \u4e0eplaywright \u5bf9\u6bd4<\/p>\n<p>Pyppeteer \u548c Playwright \u90fd\u662f\u7528\u4e8e\u63a7\u5236\u65e0\u5934\u6d4f\u89c8\u5668\u7684\u5e93&#xff0c;\u4f46\u5b83\u4eec\u5728\u8bbe\u8ba1\u548c\u529f\u80fd\u4e0a\u6709\u4e00\u4e9b\u5173\u952e\u533a\u522b&#xff1a;<\/p>\n<h4>1. \u57fa\u7840\u548c\u652f\u6301<\/h4>\n<ul>\n<li>\n<p>Pyppeteer&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u662f Puppeteer Python \u7684\u7aef\u53e3&#xff0c;\u4e3b\u8981\u9488\u5bf9 Chromium\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ea\u652f\u6301 Chrome\/Chromium&#xff0c;\u7f3a\u4e4f\u5bf9\u5176\u4ed6\u6d4f\u89c8\u5668\u7684\u652f\u6301\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Playwright&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7531 Microsoft \u5f00\u53d1&#xff0c;\u652f\u6301\u591a\u79cd\u6d4f\u89c8\u5668&#xff08;Chromium\u3001Firefox \u548c WebKit&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u66f4\u52a0\u73b0\u4ee3\u5316&#xff0c;\u8bbe\u8ba1\u7528\u4e8e\u8de8\u6d4f\u89c8\u5668\u6d4b\u8bd5\u548c\u81ea\u52a8\u5316\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. \u529f\u80fd<\/h4>\n<ul>\n<li>\n<p>Pyppeteer&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd\u8f83\u4e3a\u57fa\u7840&#xff0c;\u9002\u5408\u7b80\u5355\u7684\u81ea\u52a8\u5316\u4efb\u52a1\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u4f9b\u5e38\u89c1\u7684\u6d4f\u89c8\u5668\u64cd\u4f5c&#xff0c;\u5982\u5bfc\u822a\u3001\u622a\u5c4f\u3001\u586b\u8868\u7b49\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Playwright&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd\u66f4\u4e3a\u5f3a\u5927&#xff0c;\u652f\u6301\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\u3001\u591a\u4e2a\u6807\u7b7e\u9875\u3001\u7f51\u7edc\u62e6\u622a\u548c\u6a21\u62df\u8bbe\u5907\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u4f9b\u66f4\u4e30\u5bcc\u7684 API&#xff0c;\u652f\u6301\u7b49\u5f85\u5143\u7d20\u3001\u64cd\u4f5c\u4e8b\u4ef6\u3001\u8fd0\u884c\u811a\u672c\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>3. \u5f02\u6b65\u652f\u6301<\/h4>\n<ul>\n<li>\n<p>Pyppeteer&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528 Python \u7684 asyncio \u8fdb\u884c\u5f02\u6b65\u64cd\u4f5c&#xff0c;\u8bed\u6cd5\u76f8\u5bf9\u7b80\u5355&#xff0c;\u4f46\u53ef\u80fd\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u591f\u7075\u6d3b\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Playwright&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e5f\u4f7f\u7528 asyncio\u5e93&#xff0c;\u5e76\u4e14\u5728\u5f02\u6b65\u64cd\u4f5c\u4e0a\u8868\u73b0\u66f4\u597d&#xff0c;\u652f\u6301\u66f4\u590d\u6742\u7684\u7528\u4f8b\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4. \u6587\u6863\u548c\u793e\u533a\u652f\u6301<\/h4>\n<ul>\n<li>\n<p>Pyppeteer&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6587\u6863\u76f8\u5bf9\u7b80\u5355&#xff0c;\u793e\u533a\u652f\u6301\u8f83\u5c11\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Playwright&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u62e5\u6709\u66f4\u5b8c\u5584\u7684\u6587\u6863\u548c\u6d3b\u8dc3\u7684\u793e\u533a&#xff0c;\u95ee\u9898\u548c\u65b0\u7279\u6027\u66f4\u65b0\u9891\u7e41\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>5. \u5b89\u88c5\u548c\u4f7f\u7528<\/h4>\n<ul>\n<li>\n<p>Pyppeteer&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5b89\u88c5\u7b80\u5355&#xff0c;\u4f46\u9700\u8981\u6ce8\u610f Chromium \u7684\u4e0b\u8f7d\u548c\u7ba1\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Playwright&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5b89\u88c5\u66f4\u65b9\u4fbf&#xff0c;\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u6240\u9700\u7684\u6d4f\u89c8\u5668&#xff0c;\u5e76\u4e14\u652f\u6301\u591a\u4e2a\u6d4f\u89c8\u5668\u7684\u5b89\u88c5\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf23\u6b21\u3002Pyppeteer \u6a21\u62df\u6d4f\u89c8\u5668\u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u95ee\u9898,\u5904\u7406\u65b9\u5f0f_pyppeteer playwright<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2329,2328,81,43],"topic":[],"class_list":["post-28841","post","type-post","status-publish","format-standard","hentry","category-server","tag-playwright","tag-pyppeteer","tag-python","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/28841.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf23\u6b21\u3002Pyppeteer \u6a21\u62df\u6d4f\u89c8\u5668\u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u95ee\u9898,\u5904\u7406\u65b9\u5f0f_pyppeteer playwright\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/28841.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T19:31:22+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28841.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/28841.html\",\"name\":\"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T19:31:22+00:00\",\"dateModified\":\"2025-04-19T19:31:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/28841.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/28841.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/28841.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/28841.html","og_locale":"zh_CN","og_type":"article","og_title":"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf23\u6b21\u3002Pyppeteer \u6a21\u62df\u6d4f\u89c8\u5668\u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u95ee\u9898,\u5904\u7406\u65b9\u5f0f_pyppeteer playwright","og_url":"https:\/\/www.wsisp.com\/helps\/28841.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T19:31:22+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/28841.html","url":"https:\/\/www.wsisp.com\/helps\/28841.html","name":"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T19:31:22+00:00","dateModified":"2025-04-19T19:31:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/28841.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/28841.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/28841.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python pyppeteer \u4e0eplaywright \u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42 \u90e8\u7f72\u670d\u52a1\u5668\u9047\u5230\u7684\u5751"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=28841"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/28841\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=28841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=28841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=28841"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=28841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}