{"id":20067809,"url":"https://github.com/dean9703111/ithelp_total_count","last_synced_at":"2026-05-07T23:45:15.582Z","repository":{"id":106083234,"uuid":"444324721","full_name":"dean9703111/ithelp_total_count","owner":"dean9703111","description":"計算 IT邦幫忙文章的瀏覽/Like/留言總數","archived":false,"fork":false,"pushed_at":"2022-03-21T08:36:58.000Z","size":154,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T11:18:23.828Z","etag":null,"topics":["crawler","ithelp","total-likes","total-responses","total-views"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dean9703111.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-04T07:25:20.000Z","updated_at":"2022-01-04T09:58:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"1ef6919e-469e-49a2-a57b-825c8bf027f4","html_url":"https://github.com/dean9703111/ithelp_total_count","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"c90c55e81276ce5fb39ee10e87aac4faf77d9734"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dean9703111/ithelp_total_count","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dean9703111%2Fithelp_total_count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dean9703111%2Fithelp_total_count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dean9703111%2Fithelp_total_count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dean9703111%2Fithelp_total_count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dean9703111","download_url":"https://codeload.github.com/dean9703111/ithelp_total_count/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dean9703111%2Fithelp_total_count/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32760958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crawler","ithelp","total-likes","total-responses","total-views"],"created_at":"2024-11-13T14:03:53.539Z","updated_at":"2026-05-07T23:45:15.533Z","avatar_url":"https://github.com/dean9703111.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 計算自己 IT 邦幫忙所有文章的瀏覽/Like/留言總數的工具\n\n我想應該有許多 IT 邦幫忙的作者都很關心自己文章的瀏覽數，像筆者就是一個喜歡三不五時去看看自己文章增加多少瀏覽量的人；剛好有其他創作者反映希望可以透過工具取得自己所有文章的瀏覽/Like/留言總數，而不是靠計算機土法煉鋼來計算。\n\n藉此機會筆者就研究了一下「puppeteer」這個套件的用法，再花一點時間把小工具寫出來，完整的程式碼如下：\n\n- **main.js**\n\n  ```js\n  const puppeteer = require(\"puppeteer\");\n  require(\"dotenv\").config();\n\n  (async () =\u003e {\n    const ithelp_url = process.env.ITHELP_URL || \"https://google.com/\";\n    const browser = await puppeteer.launch({\n      headless: process.env.HEADLESS == \"false\" ? false : true,\n    });\n\n    let total_likes = 0;\n    let total_responses = 0;\n    let total_views = 0;\n    let p = 0;\n    //end = false時while迴圈會中斷\n    let end = true;\n    const page = await browser.newPage();\n    while (end) {\n      p == 0 ? await page.goto(ithelp_url) : await page.goto(ithelp_url + `?page=` + p);\n      await page.waitForSelector(\".profile-main__title\");\n\n      let elements = await page.$$(\".qa-condition__count\");\n      if (elements.length \u003e 0) {\n        for (var i = 0; i \u003c elements.length; i++) {\n          let tmp_text = await page.evaluate((el) =\u003e el.textContent, elements[i]);\n          if (i % 3 == 0) {\n            total_likes += parseInt(tmp_text);\n          } else if (i % 3 == 1) {\n            total_responses += parseInt(tmp_text);\n          } else if (i % 3 == 2) {\n            total_views += parseInt(tmp_text);\n          }\n        }\n      } else {\n        await browser.close();\n        end = false;\n      }\n      p++;\n    }\n    console.log({ \"toal likes\": total_likes, \"toal responses\": total_responses, \"toal views\": total_views });\n  })();\n  ```\n\n- **.env**\n  ```sh\n  # 填上自己想要爬蟲的頁面，下面是筆者個人的文章頁面喔\n  ITHELP_URL=https://ithelp.ithome.com.tw/users/20103256/articles\n  # 預設不開啟瀏覽器，如果你想開啟就改成false\n  HEADLESS=false\n  ```\n\n大家也可以到筆者的 [Gihub](https://github.com/dean9703111/ithelp_total_count) 直接把專案 Clone 下來執行，下面是用筆者在 IT 邦幫忙文章網址的 Demo：\n\n- 使用鐵人賽文章網址：https://ithelp.ithome.com.tw/users/20103256/ironman/4227\n  ![image](./img/ironman.png)\n- 使用個人文章網址：https://ithelp.ithome.com.tw/users/20103256/articles\n  ![image](./img/articles.png)\n\n### 專案使用提醒：\n\n- 去「.env」裡面把「ITHELP_URL」改成自己的網址\n- 如果你想要看到瀏覽器彈出來，去「.env」裡面把「HEADLESS」改成 false\n- 記得先在終端機輸入`yarn`將套件安裝\n- 在終端機輸入`yarn start`即可執行\n\n---\n\n感謝大家的閱讀，如果工具有幫助到你，按`STAR`⭐⭐⭐ 可以讓我更有開發小工具的動力。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdean9703111%2Fithelp_total_count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdean9703111%2Fithelp_total_count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdean9703111%2Fithelp_total_count/lists"}