{"id":5824,"date":"2020-02-13T20:07:38","date_gmt":"2020-02-13T11:07:38","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=5824"},"modified":"2020-02-13T20:07:38","modified_gmt":"2020-02-13T11:07:38","slug":"%e3%82%b3%e3%83%94%e3%83%9a%e3%81%a7%e7%b0%a1%e5%8d%98%ef%bc%81puppeteer%e3%81%ae%e3%81%93%e3%82%93%e3%81%aa%e3%81%a8%e3%81%8d%e5%ae%9f%e4%be%8b%ef%bc%98%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=5824","title":{"rendered":"\u30b3\u30d4\u30da\u3067\u7c21\u5358\uff01puppeteer\u306e\u3053\u3093\u306a\u3068\u304d\u5b9f\u4f8b\uff18\u4ef6"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u3068\u3053\u308d<code>Node.js<\/code>\uff08Express\uff09\u3067\u306e\u958b\u767a\u3092\u7d9a\u3051\u3066\u3044\u3066\u8272\u3005\u3068\u65b0\u3057\u3044\u6280\u8853\u3084\u958b\u767a\u601d\u60f3\u306b\u89e6\u308c\u308b\u6a5f\u4f1a\u3092\u591a\u304f\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u307e\u3060\u307e\u3060\u5b66\u3076\u3053\u3068\u306f\u591a\u3044\u306e\u3067\u3059\u304c\u3001<code>Node.js<\/code>\u3092\u4f7f\u3063\u305f\u958b\u767a\u306f\u3042\u308b\u7a0b\u5ea6\u7406\u89e3\u304c\u6df1\u307e\u3063\u3066\u304d\u305f\u306e\u3067\u3001\u3053\u306e\u8fba\u3067\u3001\u300c<strong>\u3053\u308c\u306f\u4eca\u5f8c\u3082\u4f7f\u3044\u305d\u3046\u3002\u3067\u3082\u3001\u3061\u3087\u3063\u3068\u8907\u96d1\u3067\u3059\u3050\u5fd8\u308c\u3061\u3083\u3044\u305d\u3046\u30fb\u30fb\u30fb<\/strong>\ud83d\ude05\u300d\u3068\u3044\u3046\u5185\u5bb9\u3092\u5099\u5fd8\u9332\u7684\u306b\u307e\u3068\u3081\u3066\u304a\u304f\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u300c\u5b9f\u969b\u306e\u30d6\u30e9\u30a6\u30b6\u3092\u4f7f\u3063\u3066\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u300d<code>puppeteer<\/code>\u3092\u4f7f\u3063\u305f\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u3092\u3054\u7d39\u4ecb\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b<code>puppeteer<\/code>\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u3084\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u3001\u4ee5\u524d\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=5321\">JavaScript\u3067\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3057\u3066\u308b\u30da\u30fc\u30b8\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u305d\u3061\u3089\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2173 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png\" alt=\"\" width=\"300\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24-281x300.png 281w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong>Node.js 8<\/p>\n<h1>\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u3084JavaScript\u3001\u753b\u50cf\u306a\u3069\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307e\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p><a name=\"cancel_loading\"><\/a><\/p>\n<p>\u5927\u591a\u6570\u306e\u30a6\u30a7\u30d6\u30da\u30fc\u30b8\u3067\u306f\u3001\u3072\u3068\u3064\u306e\u30da\u30fc\u30b8\u3060\u3051\u3067\u306a\u304f\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u3084JavaScript\u3001\u753b\u50cf\u306a\u3069\u3092\u4f7f\u3063\u3066\u88c5\u98fe\u3084\u52d5\u304d\u3092\u52a0\u3048\u3066\u3044\u307e\u3059\u3002\u3055\u3089\u306b\u305d\u308c\u3089\u306f\u3001<code>.css<\/code>\u3084<code>.js<\/code>\u306a\u3069\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u5316\u3057\u3066\u3044\u308b\u5834\u5408\u304c\u591a\u3044\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u305f\u3060\u3001\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3092\u3059\u308b\u5834\u5408\u306b\u306f\u3053\u3046\u3044\u3063\u305f\u300c\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u300d\u304c\u4e0d\u8981\u3060\u3063\u305f\u308a\u3059\u308b\u5834\u5408\u304c\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u306b\u3088\u308a<code>puppeteer<\/code>\u306f<code>chrome<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u3068\u306f\u3044\u3048\u3001\u5168\u3066\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3057\u307e\u3046\u3068\u30b5\u30fc\u30d0\u30fc\u306b\u8ca0\u8377\u304c\u304b\u304b\u308a\u3059\u304e\u3066\u52d5\u304b\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3093\u306a\u5834\u5408\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u4e0d\u8981\u306aURL\u306f\u4e8b\u524d\u306b\u8aad\u307f\u8fbc\u307f\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.setRequestInterception(true);\r\n<strong>    page.on('request', request =&gt; {<\/strong>\r\n\r\n<strong>        const requestType = request.resourceType();<\/strong>\r\n\r\n<strong>        if(requestType === 'document') {<\/strong>  \/\/ \u6587\u66f8\u30d5\u30a1\u30a4\u30eb\u306e\u307fOK\r\n\r\n<strong>            request.continue();<\/strong> \/\/ \u7d9a\u3051\u3066\u8aad\u307f\u8fbc\u3080\r\n\r\n<strong>        } else {<\/strong>\r\n\r\n<strong>            request.abort();<\/strong>  \/\/ \u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u306f\u8aad\u307f\u8fbc\u307e\u306a\u3044\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n    await page.goto('https:\/\/www.yahoo.co.jp\/');\r\n    const headingText = await page.evaluate(() =&gt; {\r\n\r\n        return document.querySelector('h1').innerText;  \/\/ h1\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\r\n\r\n    });\r\n    await browser.close();\r\n\r\n    console.log(headingText); \/\/ Yahoo! JAPAN\r\n\r\n})();<\/pre>\n<p>\u6d41\u308c\u3068\u3057\u3066\u306f\u3001<code>Chrome<\/code>\u304c\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u3059\u308b\u76f4\u524d\u306b<code>abort()<\/code>\u3092\u4f7f\u3063\u3066\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u3088\u308a\u7d30\u304b\u304f\u30a2\u30af\u30bb\u30b9\u3059\u308bURL\u3092\u5206\u3051\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u304c<code>resourceType()<\/code>\u3067\u53d6\u5f97\u3067\u304d\u308b\u30ea\u30bd\u30fc\u30b9\u30bf\u30a4\u30d7\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001<code>if<\/code>\u6587\u306a\u3069\u3067\u5236\u5fa1\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>document<\/li>\n<li>stylesheet<\/li>\n<li>image<\/li>\n<li>media<\/li>\n<li>font<\/li>\n<li>script<\/li>\n<li>texttrack<\/li>\n<li>xhr<\/li>\n<li>fetch<\/li>\n<li>eventsource<\/li>\n<li>websocket<\/li>\n<li>manifest<\/li>\n<li>other<\/li>\n<\/ul>\n<h1>iFrame\u3092\u8aad\u307f\u8fbc\u307e\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p>\u57fa\u672c\u7684\u306b\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3092\u906e\u65ad\u3059\u308b\u306b\u306f\u3001\u524d\u9805\u76ee\u306e\u300c<a href=\"#cancel_loading\">\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u3084JavaScript\u3001\u753b\u50cf\u306a\u3069\u306e\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307e\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/a>\u300d\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u304c\u3001\u5b9f\u306f<code>iFrame<\/code>\u3060\u3051\u306f\u30ea\u30bd\u30fc\u30b9\u30bf\u30a4\u30d7\u304c\u540c\u3058\u304f<code>document<\/code>\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u305d\u308c\u3060\u3051\u3067\u306f\u906e\u65ad\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001<code>iFrame<\/code>\u306e\u906e\u65ad\u3092\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>frameattached<\/code>\u3092\u4f7f\u3063\u3066\u300c<strong>\u6b21\u8aad\u307f\u8fbc\u3080URL\u306fiFrame\u306e\u3082\u306e\u306a\u306e\u304b\u3069\u3046\u304b<\/strong>\u300d\u3067\u5224\u5225\u3057\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.setRequestInterception(true);\r\n\r\n    <strong>let isIframe = false; \/\/ iFrame\u304b\u3069\u3046\u304b\u3092\u5224\u5225\u3059\u308b\u5909\u6570<\/strong>\r\n\r\n    page.on('request', request =&gt; {\r\n\r\n        const requestType = request.resourceType();\r\n\r\n        if(requestType === 'document' &amp;&amp; <strong>!isIframe<\/strong>) {  \/\/ \u6587\u66f8\u30d5\u30a1\u30a4\u30eb\u306e\u307fOK\r\n\r\n            request.continue(); \/\/ \u7d9a\u3051\u3066\u8aad\u307f\u8fbc\u3080\r\n\r\n        } else {\r\n\r\n            request.abort();  \/\/ iFrame\u3001\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u306f\u8aad\u307f\u8fbc\u307e\u306a\u3044\r\n\r\n        }\r\n\r\n        <strong>isIframe = false;<\/strong> \/\/ iFrame\u306e\u7d50\u679c\u3092\u521d\u671f\u5316\r\n\r\n    });\r\n    <strong>page.on('frameattached', frame =&gt; {<\/strong>\r\n\r\n<strong>        isIframe = true; \/\/ iFrame\u306e\u8aad\u307f\u8fbc\u307f\u306e\u5834\u5408\u306f \"true\" \u306b\u306a\u308b<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n    await page.goto('https:\/\/www.w3schools.com\/html\/html_iframe.asp');\r\n    const headingText = await page.evaluate(() =&gt; {\r\n\r\n        return document.querySelector('h1').innerText;  \/\/ h1\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\r\n\r\n    });\r\n    await browser.close();\r\n\r\n    console.log(headingText); \/\/ HTML Iframes\r\n\r\n})();<\/pre>\n<h1>HTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u30a2\u30af\u30bb\u30b9\u304c\u3046\u307e\u304f\u3044\u3063\u305f\u3068\u304d\u306e<code>200<\/code>\u3084\u30da\u30fc\u30b8\u304c\u5b58\u5728\u3057\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3059\u308b<code>404<\/code>\u3001\u30a8\u30e9\u30fc\u306e<code>500<\/code>\u306a\u3069\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3001<code>response<\/code>\u3092\u8aad\u307f\u53d6\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.setRequestInterception(true);\r\n    page.on('request', request =&gt; {\r\n\r\n        const requestType = request.resourceType();\r\n\r\n        if(requestType === 'document') {\r\n\r\n            request.continue();\r\n\r\n        } else {\r\n\r\n            request.abort();\r\n\r\n        }\r\n\r\n    });\r\n\r\n<strong>    let statusCode = 0;<\/strong>\r\n\r\n<strong>    page.on('response', response =&gt; {<\/strong>\r\n\r\n<strong>        statusCode = response.status(); \/\/ HTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n    await page.goto('https:\/\/www.yahoo.co.jp\/');\r\n    const headingText = await page.evaluate(() =&gt; {\r\n\r\n        return document.querySelector('h1').innerText;  \/\/ h1\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\r\n\r\n    });\r\n    await browser.close();\r\n\r\n    console.log(<strong>statusCode<\/strong>); \/\/ 200\r\n\r\n})();<\/pre>\n<p>\u306a\u304a\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u30fc\u5168\u3066\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3001<code>response.headers()<\/code>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3001\u53d6\u5f97\u3067\u304d\u308b\u30c7\u30fc\u30bf\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<pre>{\r\n    status: '200',\r\n    'content-encoding': 'gzip',\r\n    'accept-ranges': 'bytes',\r\n    'cache-control': 'max-age=604800',\r\n    'content-type': 'text\/html; charset=UTF-8',\r\n    date: 'Thu, 13 Feb 2020 10:19:08 GMT',\r\n    etag: '\"3147526947+gzip\"',\r\n    expires: 'Thu, 20 Feb 2020 10:19:08 GMT',\r\n    'last-modified': 'Thu, 17 Oct 2019 07:18:26 GMT',\r\n    server: 'EOS (vny\/0452)',\r\n    vary: 'Accept-Encoding'\r\n}<\/pre>\n<h1>jQuery\u3092\u633f\u5165\u3059\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001<a href=\"https:\/\/www.yahoo.co.jp\/\" target=\"_blank\" rel=\"noopener noreferrer\">Yahoo! JAPAN<\/a>\u306b\u306f<code>jQuery<\/code>\u306f\u4f7f\u308f\u308c\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u5f37\u5236\u7684\u306b<code>cdn<\/code>\u306e<code>jQuery<\/code>\u3092\u8aad\u307f\u8fbc\u307e\u305b\u3066<code>$()<\/code>\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n<strong>const JQUERY_URL = 'https:\/\/code.jquery.com\/jquery-3.4.1.min.js';<\/strong>\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.setRequestInterception(true);\r\n    page.on('request', request =&gt; {\r\n\r\n        const requestType = request.resourceType();\r\n        const requestUrl = request.url();\r\n\r\n        if(requestType === 'document' || <strong>requestUrl === JQUERY_URL<\/strong>) {\r\n\r\n            \/\/ \u901a\u5e38\u30da\u30fc\u30b8\u3068jQuery\u3060\u3051\u306f\u8aad\u307f\u8fbc\u3080\r\n            request.continue();\r\n\r\n        } else {\r\n\r\n            \/\/ \u305d\u308c\u4ee5\u5916\u306f\u8aad\u307f\u8fbc\u307f\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\r\n            request.abort();\r\n\r\n        }\r\n\r\n    });\r\n    await page.goto('https:\/\/www.yahoo.co.jp\/');\r\n    <strong>await page.addScriptTag({ url: JQUERY_URL });<\/strong> \/\/ jQuery\u3092\u5f37\u5236\u7684\u306b\u8aad\u307f\u8fbc\u307e\u305b\u308b\r\n    const headingText = await page.evaluate(() =&gt; {\r\n\r\n        return <strong>$('title').text();<\/strong>  \/\/ jQuery\u3092\u4f7f\u3063\u3066\u30da\u30fc\u30b8\u30bf\u30a4\u30c8\u30eb\u3092\u53d6\u5f97\r\n\r\n    });\r\n    await browser.close();\r\n\r\n    console.log(headingText); \/\/ Yahoo! JAPAN\r\n\r\n})();<\/pre>\n<h1>POST\u9001\u4fe1\u3059\u308b<\/h1>\n<p>POST\u30e1\u30bd\u30c3\u30c9\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>continue()<\/code>\u3067\u30e1\u30bd\u30c3\u30c9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.setRequestInterception(true);\r\n    page.on('request', request =&gt; {\r\n\r\n        const requestType = request.resourceType();\r\n\r\n        if(requestType === 'document') {\r\n\r\n            <strong>request.continue({ method: 'POST' });<\/strong> \/\/ POST\u30e1\u30bd\u30c3\u30c9\u3067\u30a2\u30af\u30bb\u30b9\r\n\r\n        } else {\r\n\r\n            request.abort();\r\n\r\n        }\r\n\r\n    });\r\n    await page.goto('https:\/\/example.com\/');\r\n    const headingText = await page.evaluate(() =&gt; {\r\n\r\n        return document.querySelector('h1').innerText;\r\n\r\n    });\r\n    await browser.close();\r\n\r\n    console.log(headingText); \/\/ Example Domain\r\n\r\n})();<\/pre>\n<h1>\u30e6\u30fc\u30b6\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3092\u30bb\u30c3\u30c8\u3059\u308b<\/h1>\n<p>\u30e6\u30fc\u30b6\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3068\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3084\u30a2\u30af\u30bb\u30b9\u74b0\u5883\u3092\u8b58\u5225\u3059\u308b\u305f\u3081\u306a\u3069\u306b\u3064\u304b\u308f\u308c\u3066\u3044\u308b\u6587\u5b57\u5217\u306e\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u3044\u3046\u3068\u300c<strong>\u79c1\u306fGoogle Chrome\u3067\u3059\uff01<\/strong>\u300d\u306a\u3069\u3068\u540d\u4e57\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6587\u5b57\u5217\u3067\u3059\u3002\uff08\u3064\u307e\u308a\u507d\u88c5\u306f\u3068\u3066\u3082\u7c21\u5358\u3068\u3044\u3046\u3053\u3068\u3067\u3059\uff09<\/p>\n<p>\u3010\u30e6\u30fc\u30b6\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306e\u4f8b\u3011<\/p>\n<pre>Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/80.0.3987.100 Safari\/537.36<\/pre>\n<p>\u30e6\u30fc\u30b6\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u3092\u30bb\u30c3\u30c8\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>const browser = await puppeteer.launch();\r\nconst page = await browser.newPage();\r\n<strong>await page.setUserAgent('Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/80.0.3987.100 Safari\/537.36');\r\n<\/strong>\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u203b\u3061\u306a\u307f\u306b<a href=\"https:\/\/japan.cnet.com\/article\/35147994\/\" target=\"_blank\" rel=\"noopener noreferrer\">cnet\u306e\u8a18\u4e8b<\/a>\u306b\u3088\u308b\u3068\u3001<code>Google Chrome<\/code>\u3067\u306f\u3053\u306e\u30e6\u30fc\u30b6\u30fc\u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u306e\u6a5f\u80fd\u3092\u4eca\u5f8c\u7e2e\u5c0f\u3057\u3066\u3044\u304f\u65b9\u91dd\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<h1>Cookie\u3092\u8ffd\u52a0\u3059\u308b<\/h1>\n<p>\u7279\u5b9a\u306e<code>Cookie<\/code>\u3092\u30bb\u30c3\u30c8\u3057\u3066\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001<code>setCookie()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>const cookies = [<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        'name': 'YOUR-COOKIE-NAME',<\/strong>\r\n<strong>        'value': 'YOUR-COOKIE-VALUE',<\/strong>\r\n<strong>        'domain': 'www.example.com',<\/strong> \/\/ \u30c9\u30e1\u30a4\u30f3\uff08\u7701\u7565\u53ef\uff09\r\n<strong>        'path': '\/'<\/strong> \/\/ \u30d1\u30b9\uff08\u7701\u7565\u53ef\uff09\r\n<strong>    }<\/strong>\r\n<strong>];<\/strong>\r\n\r\nconst browser = await puppeteer.launch();\r\nconst page = await browser.newPage();\r\n<strong>page.setCookie(...cookies);<\/strong><\/pre>\n<p>\u203b<code>Cookie<\/code>\u306e\u5185\u5bb9\u306f\u914d\u5217\u3067\u3044\u304f\u3064\u3067\u3082\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u3068\u308b<\/h1>\n<p>\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u3068\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>const puppeteer = require('puppeteer');\r\n\r\n(async () =&gt; {\r\n\r\n    const browser = await puppeteer.launch();\r\n    const page = await browser.newPage();\r\n    await page.goto('http:\/\/example.com\/');\r\n    <strong>await page.screenshot({path: '.\/screenshot.png'});<\/strong>\r\n\r\n})();<\/pre>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Node.js<\/code>\u306e\u5f37\u529b\u306a\u6b66\u5668\u3068\u3044\u3063\u3066\u3082\u3044\u3044<code>puppeteer<\/code>\u306e\u4f7f\u3044\u65b9\u3092\u30b1\u30fc\u30b9\u3054\u3068\u306b\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305f\u3060\u3001<code>puppeteer<\/code>\u306f\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u4ee5\u5916\u306b\u3082\u8272\u3005\u306a\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u4eca\u5f8c\u4f55\u304b\u300c\u304a\u3063\uff01\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u305d\u306e\u90fd\u5ea6\u3053\u306e\u30da\u30fc\u30b8\u306b\u8ffd\u52a0\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u3054\u671f\u5f85\u4e0b\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2597 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png\" alt=\"\" width=\"275\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png 275w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2-236x300.png 236w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u3068\u3053\u308dNode.js\uff08Express\uff09\u3067\u306e\u958b\u767a\u3092\u7d9a\u3051\u3066\u3044\u3066\u8272\u3005\u3068\u65b0\u3057\u3044\u6280\u8853\u3084\u958b\u767a\u601d\u60f3\u306b\u89e6\u308c\u308b\u6a5f\u4f1a\u3092\u591a\u304f\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002 \u3082\u3061\u308d\u3093\u307e\u3060\u307e\u3060\u5b66\u3076 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=5824\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30b3\u30d4\u30da\u3067\u7c21\u5358\uff01puppeteer\u306e\u3053\u3093\u306a\u3068\u304d\u5b9f\u4f8b\uff18\u4ef6&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":5828,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[204,194],"class_list":["post-5824","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","tag-puppeteer","tag-194"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5824"}],"version-history":[{"count":9,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5824\/revisions"}],"predecessor-version":[{"id":5834,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5824\/revisions\/5834"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/5828"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}