{"id":1654,"date":"2022-03-21T16:00:20","date_gmt":"2022-03-21T07:00:20","guid":{"rendered":"https:\/\/dalomo.net\/blog\/?p=1654"},"modified":"2022-03-21T16:06:20","modified_gmt":"2022-03-21T07:06:20","slug":"%e5%8b%95%e7%9a%84%e3%81%ab%e3%82%b3%e3%83%b3%e3%83%86%e3%83%b3%e3%83%84%e3%82%92%e7%94%9f%e6%88%90%e3%81%97%e3%81%a6%e3%82%8b%e3%82%b5%e3%82%a4%e3%83%88%e3%82%92%e3%82%af%e3%83%ad%e3%83%bc%e3%83%a9","status":"publish","type":"post","link":"https:\/\/dalomo.net\/blog\/2022\/03\/21\/1654\/","title":{"rendered":"\u52d5\u7684\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u751f\u6210\u3057\u3066\u308b\u30b5\u30a4\u30c8\u3092\u30af\u30ed\u30fc\u30e9\u30fcbot\u306b\u8aad\u307e\u305b\u305f\u3044"},"content":{"rendered":"<h1>Javascript\u30b3\u30f3\u30c6\u30f3\u30c4<\/h1>\n<p>Google\u306e\u30af\u30ed\u30fc\u30e9\u30fc\u306f\u5de1\u56de\u6642\u306b\u30b5\u30a4\u30c8\u306eJavascript\u3092\u5b9f\u884c\u3057\u306a\u3044\u3089\u3057\u3044\u3002\u305d\u3046\u3059\u308b\u3068\u4fdd\u5b58\u3055\u308c\u308b\u30b3\u30f3\u30c6\u30f3\u30c4\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u4e2d\u8eab\u30b9\u30ab\u30b9\u30ab\u306e\u72b6\u614b\u3060\u3002\u3066\u306a\u308b\u3068\u691c\u7d22\u306b\u5f15\u3063\u304b\u304b\u308a\u306b\u304f\u304f\u306a\u308b\u3057\u3001\u63a2\u3055\u308c\u3065\u3089\u304f\u306a\u308b\u3002Google\u3055\u3093\u304cJS\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3057\u3066\u304f\u308c\u308b\u306e\u304c\u3044\u3044\u3068\u601d\u3046\u3093\u3060\u3051\u3069\u3001\u73fe\u72b6\u305d\u3046\u306a\u3063\u3066\u306a\u3044\u306e\u3067\u3053\u3061\u3089\u3067\u30af\u30ed\u30fc\u30e9\u30fc\u7528\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u7528\u610f\u3057\u3066\u3042\u3052\u308b\u3068\u304b\u304c\u3042\u308b(\u30d7\u30ea\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0)\u3002<a href=\"https:\/\/dalomo.net\/hotwee\/\">\u307b\u3063\u3064\u3044\uff01<\/a>\u3082\u305d\u3046\u3044\u3046\u611f\u3058\u306b\u3057\u3066\u307f\u305f\u3044\u3002<\/p>\n<h2>\u65b9\u91dd<\/h2>\n<p>Google\u304b\u3089\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u60c5\u5831\u3068\u3057\u3066\u3001\u3053\u3061\u3089\u306e<\/p>\n<p><a href=\"https:\/\/developers.google.com\/search\/docs\/advanced\/javascript\/javascript-seo-basics?hl=ja\">https:\/\/developers.google.com\/search\/docs\/advanced\/javascript\/javascript-seo-basics?hl=ja<\/a><\/p>\n<p>\u4e00\u9023\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u3042\u308b\u3002\u3067\u3001\u3053\u306e\u4e2d\u306e\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3092\u5b9f\u88c5\u3057\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u305f\u306e\u3060\u3051\u3069\u3001\u3053\u3053\u3067\u89e3\u8aac\u3055\u308c\u3066\u3044\u308b\u65b9\u6cd5\u306fRendertron\u3092\u4f7f\u3063\u3066\u9759\u7684HTML\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3059\u65b9\u6cd5\u3060\u3002<\/p>\n<p><a href=\"https:\/\/codelabs.developers.google.com\/codelabs\/dynamic-rendering\">https:\/\/codelabs.developers.google.com\/codelabs\/dynamic-rendering<\/a><\/p>\n<p>Rendertron\u306f\u5185\u90e8\u306bPuppeteer\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u3001\u8a66\u3057\u3066\u306a\u3044\u3051\u3069\u8aac\u660e\u3092\u898b\u308b\u9650\u308a\u3067\u306f1\u30a2\u30af\u30bb\u30b9\u3054\u3068\u306b1\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3057\u3066\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u9001\u308b\u3088\u3046\u306a\u5f62\u3067\u5b9f\u88c5\u3057\u3066\u3044\u308b\u307f\u305f\u3044\u3002\u3059\u3067\u306b\u81ea\u5206\u306fSelenium\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u308b\u306e\u306b\u52a0\u3048\u3066\u3001\u9010\u6b21\u7684\u306a\u5b9f\u884c\u306f\u30b5\u30fc\u30d0\u30fc\u306e\u30ea\u30bd\u30fc\u30b9\u7684\u306b\u512a\u3057\u304f\u306a\u3055\u305d\u3046\u3060\u306a\u30fc\u3068\u601d\u3063\u305f\u3002\u306e\u3067\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u306f\u306a\u304f\u306a\u308b\u3082\u306e\u306e\u3001\u30af\u30ed\u30fc\u30e9\u30fc\u306e\u983b\u5ea6\u3082\u305d\u3093\u306a\u306b\u9ad8\u304f\u306d\u30fc\u3060\u308d\u3068\u601d\u3063\u305f\u306e\u3067\u30d7\u30ea\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3057\u305f\u9759\u7684\u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u3066\u304a\u304d\u3001bot\u304c\u6765\u305f\u3068\u304d\u3060\u3051\u305d\u3063\u3061\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u898b\u305b\u308b\u3088\u3046\u306a\u5b9f\u88c5\u306b\u3057\u3088\u3046\u3068\u8003\u3048\u305f\u3002\u305d\u3046\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>isbot\u3067\u30a2\u30af\u30bb\u30b9\u304cbot\u306e\u3082\u306e\u304b\u5426\u304b\u3092\u5224\u65ad\u3059\u308b<\/h2>\n<p>isbot\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3055\u305b\u3066\u3082\u3089\u3046\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/omrilotan\/isbot\">https:\/\/github.com\/omrilotan\/isbot<\/a><\/p>\n<p>\u6709\u5fd7\u306b\u3088\u3063\u3066\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u30af\u30ed\u30fc\u30e9\u30fcbot\u30ea\u30b9\u30c8\u3092\u3082\u3068\u306bUserAgent\u3068\u6bd4\u8f03\u3057\u3066bot\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u3066\u304f\u308c\u308b\u30ca\u30a4\u30b9\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3060\u3063\u305f\u3002<\/p>\n<pre>$ npm i isbot<\/pre>\n<p>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u308b\u3002\u305d\u3057\u305f\u3089\u30b3\u30fc\u30c9\u5185\u3067<\/p>\n<pre><code class=\"js\">const isbot = require('isbot')<\/code><\/pre>\n<p>\u3068\u3001\u4f8b\u3048\u3070<\/p>\n<pre><code class=\"js\">app.get('\/hotwee', (req, res) =&gt; {\r\n  \r\n  if (isbot(req.header('User-Agent'))) {\r\n    console.log('bot has come : ' + req.header('User-Agent'))\r\n    res.sendFile('\/***\/rendered.html')\r\n  } else {\r\n    res.sendFile('\/***\/index.html')\r\n  }\r\n})<\/code><\/pre>\n<p>\u307f\u305f\u3044\u306a\u3002\u3053\u308c\u3067bot\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u6642\u306b\u306f\u5225\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6e21\u3059\u3068\u3044\u3046\u65b9\u6cd5\u304c\u5b9f\u73fe\u3067\u304d\u305f\u3002\u3053\u3053\u306erendered.html\u306b\u4fdd\u5b58\u3057\u3066\u3042\u3052\u308c\u3070\u3088\u3044\u306e\u3060\u306a\u3002<\/p>\n<h2>\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u5f8c\u306eHTML\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b<\/h2>\n<p>Selenium\u306b\u3088\u3063\u3066\u53d6\u5f97\u3057\u305f\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u5f8c\u306eHTML\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<pre><code class=\"python\">driver.page_source<\/code><\/pre>\n<p>\u306a\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u73fe\u5728\u306e\u30da\u30fc\u30b8\u3092\u305d\u306e\u307e\u307e\u4fdd\u5b58\u3059\u308b\u3084\u3064\u306a\u306e\u3067\u3001\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u308b\u307e\u3067\u5f85\u305f\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3002\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u305f\u3053\u3068\u3092\u53d6\u5f97\u3059\u308b\u305d\u308c\u7528\u306e\u65b9\u6cd5\u304c\u3001\u8abf\u3079\u305f\u9650\u308a\u3067\u306f\u306a\u304b\u3063\u305f\u306e\u3067\u4ee3\u66ff\u65b9\u6cd5\u3068\u3057\u3066\u3001\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u306a\u3044\u3068\u51fa\u73fe\u3057\u306a\u3044\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304d<\/p>\n<pre><code class=\"python\">driver.implicitly_wait(time)<\/code><\/pre>\n<p>\u3067\u5f85\u3064\u6700\u5927\u5024\u3092\u8a2d\u5b9a\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u5b9f\u73fe\u3057\u3088\u3046\u3068\u601d\u3046\u3002\u305f\u3060\u3001\u3060\u3068\u3057\u3066\u3082\u79d2\u6570\u307e\u3067\u306b\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u304c\u7d42\u308f\u3089\u306a\u3051\u308c\u3070\u53d6\u5f97\u306f\u3067\u304d\u306a\u3044\u3002\u2026\u307e\u3041\u3044\u3063\u304b\uff01\u3068\u3044\u3046\u304b\u7d50\u5c40time.sleep()\u3067\u5b9f\u88c5\u3057\u3061\u3083\u3063\u305f\u3002\u3053\u308c\u3060\u3068\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u51e6\u7406\u306b\u306a\u308b\u306e\u3067\u5b9f\u884c\u4e2d\u306f\u30b5\u30a4\u30c8\u6b62\u307e\u3063\u305f\u308a\u3059\u3093\u306e\u304b\u306a\u3002\u3002\u3002<\/p>\n<pre><code class=\"python\"># \u3069\u308c\u304c\u5fc5\u8981\u3067\u3069\u308c\u304c\u3044\u3089\u306a\u3044\u304b\u5fd8\u308c\u305f\u3002\r\nfrom selenium import webdriver\r\nfrom selenium.webdriver.common.by import By\r\nfrom selenium.webdriver.support.ui import WebDriverWait\r\nfrom selenium.webdriver.support import expected_conditions as EC\r\nfrom selenium.common.exceptions import TimeoutException\r\nimport chromedriver_binary\r\nimport time\r\n\r\noptions = webdriver.ChromeOptions()\r\noptions.add_argument('--headless') # \u30d8\u30c3\u30c9\u30ec\u30b9\u30e2\u30fc\u30c9\r\noptions.add_argument('--no-sandbox') # \u30b5\u30f3\u30c9\u30dc\u30c3\u30af\u30b9\u4f7f\u7528\u3057\u306a\u3044\r\nprofile_path = '\/root\/.config\/google-chrome\/default' # chrome\u306e\u500b\u4eba\u8a2d\u5b9a\u306epath\r\noptions.add_argument('--user-data-dir=' + profile_path)  # \u500b\u4eba\u8a2d\u5b9a\u3092\u5229\u7528\u3059\u308b\u3088\u3046\u8a2d\u5b9a\u3059\u308b\r\n# \u3053\u308c\u81ea\u4f53\u304cbot\u3068\u8a8d\u8b58\u3055\u308c\u308b\u306e\u3092\u9632\u3050\u305f\u3081\u9069\u5f53\u306bUserAgent\u3092\u8a2d\u5b9a\u3059\u308b\r\noptions.add_argument('--user-agent=Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/98.0.4758.82 Safari\/537.36')\r\ndriver = webdriver.Chrome(options=options) # \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u9069\u7528\r\n\r\ndriver.set_window_size(1600, 900)\r\ndriver.implicitly_wait(15)\r\n\r\ndriver.get(\"https:\/\/dalomo.net\/hotwee\")\r\n\r\ntime.sleep(10)\r\n\r\nprint(driver.page_source)\r\n\r\ndriver.quit()<\/code><\/pre>\n<p>\u6700\u7d42\u7684\u306bprint\u3092\u4f7f\u3063\u3066\u308b\u306e\u3067\u3001\u5b9f\u884c\u3059\u308b\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u306b\u30bd\u30fc\u30b9\u304c\u8868\u793a\u3055\u308c\u308b\u3002Python\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u3066\u3082\u3088\u304b\u3063\u305f\u304c\u3001\u3081\u3093\u3069\u304f\u3055\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u7c21\u5358\u306b\u30b7\u30a7\u30eb\u3067\u51fa\u529b\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002\u3064\u307e\u308a<\/p>\n<pre>0 10,22 * * * \/usr\/local\/bin\/python3 \/home\/dalomo\/hotwee\/getsource.py &gt; \/home\/dalomo\/hotwee\/public\/rendered.html<\/pre>\n<p>\u3053\u3046\u3057\u305f\u3002\u30ea\u30c0\u30a4\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u3044\u3046\u3089\u3057\u3044\u3002\u5927\u306a\u308a&gt;\u30922\u3064\u91cd\u306d\u308b\u3068&gt;&gt;\u8ffd\u8a18\u3059\u308b\u611f\u3058\u306b\u306a\u308b\u307f\u305f\u3044\u3002\u30ed\u30b0\u3068\u304b\u3067\u4f7f\u3063\u305f\u306a\u3002\u3053\u308c\u3067\u4fdd\u5b58\u304c\u3067\u304d\u305f\u308f\u3051\u3060\u3002\u78ba\u5b9f\u6027\u3068\u3044\u3046\u70b9\u3067\u306f\u3061\u3087\u3063\u3068\u52a3\u308b\u304c\u307e\u3041\u3057\u3087\u30fc\u304c\u306a\u3044\u3002\u3053\u308c\u3092cron\u306b\u767b\u9332\u3057\u3066\u304a\u304f\u3002<\/p>\n<h2>\u78ba\u8a8d<\/h2>\n<p><a href=\"https:\/\/search.google.com\/test\/mobile-friendly?hl=ja\">https:\/\/search.google.com\/test\/mobile-friendly?hl=ja<\/a><\/p>\n<p>\u3092\u4f7f\u3063\u3066\u30b5\u30a4\u30c8\u3092\u30c6\u30b9\u30c8\u3059\u308b\u3002\u81ea\u5206\u306e\u30b5\u30a4\u30c8\u3060\u3068<\/p>\n<p><a href=\"https:\/\/search.google.com\/test\/mobile-friendly\/result?id=mUYg46635timlkcvvz0zCw&amp;hl=ja\">https:\/\/search.google.com\/test\/mobile-friendly\/result?id=mUYg46635timlkcvvz0zCw&amp;hl=ja<\/a><\/p>\n<p>\u300c\u30c6\u30b9\u30c8\u6e08\u307f\u306e\u30da\u30fc\u30b8\u3092\u8868\u793a\u300d\u304b\u3089\u78ba\u8a8d\u3067\u304d\u308b\u3002\u3061\u3083\u3093\u3068\u53d6\u5f97\u3067\u304d\u3066\u308b\u306e\u3067\u304a\u3063\u3051\u30fc\u3067\u3059\u306d\u3002\u3042\u3068\u306f\u30fc\u5e83\u544a\u304c\u90aa\u9b54\u304f\u3055\u3044\u306e\u3067\u524a\u9664\u3067\u304d\u308c\u3070\u3044\u3044\u3093\u3060\u3051\u3069\u305d\u308c\u306f\u5f8c\u56de\u3057\u304b\u306a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Javascript\u30b3\u30f3\u30c6\u30f3\u30c4 Google\u306e\u30af\u30ed\u30fc\u30e9\u30fc\u306f\u5de1\u56de\u6642\u306b\u30b5\u30a4\u30c8\u306eJavascript\u3092\u5b9f\u884c\u3057\u306a\u3044\u3089\u3057\u3044\u3002\u305d\u3046\u3059\u308b\u3068\u4fdd\u5b58\u3055\u308c\u308b\u30b3\u30f3\u30c6\u30f3\u30c4\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u4e2d\u8eab\u30b9\u30ab\u30b9\u30ab\u306e\u72b6\u614b\u3060\u3002\u3066\u306a\u308b\u3068\u691c\u7d22\u306b\u5f15\u3063\u304b\u304b\u308a\u306b\u304f\u304f\u306a\u308b\u3057\u3001\u63a2\u3055 &hellip; <a href=\"https:\/\/dalomo.net\/blog\/2022\/03\/21\/1654\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[162,159],"class_list":["post-1654","post","type-post","status-publish","format-standard","hentry","category-8","tag-selenium","tag-159"],"_links":{"self":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/comments?post=1654"}],"version-history":[{"count":5,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1654\/revisions"}],"predecessor-version":[{"id":1672,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1654\/revisions\/1672"}],"wp:attachment":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media?parent=1654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/categories?post=1654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/tags?post=1654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}