From cabacc6bc2924167a81dcab4f844b53401a31f8c Mon Sep 17 00:00:00 2001 From: haturatu Date: Sun, 19 Jan 2025 16:02:43 +0900 Subject: first commit --- .gitignore | 1 + README.md | 13 +++++++++++++ curl.js | 28 ++++++++++++++++++++++++++++ package.json | 5 +++++ 4 files changed, 47 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 curl.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ff8ca9 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# curljs +This will load the website that requires JS loading. +Load JS using headless Chrome and return DOM. +## install +```bash +npm install +``` + +## Using +```bash +node curl.js "https://www.google.com/" +``` +Done! diff --git a/curl.js b/curl.js new file mode 100644 index 0000000..a75ba3d --- /dev/null +++ b/curl.js @@ -0,0 +1,28 @@ +const puppeteer = require('puppeteer'); + +(async () => { + // 第一引数からURLを取得 + const url = process.argv[2]; + if (!url) { + console.error('Error: URL not provided.'); + process.exit(1); + } + + const browser = await puppeteer.launch({ headless: true }); + const page = await browser.newPage(); + + // 特定のURLにアクセス + await page.goto(url, { + waitUntil: 'networkidle2', // ネットワークがアイドル状態になるまで待機 + }); + + // 5秒間待機 + await page.waitForTimeout(5000); + + // ページのHTMLを取得 + const html = await page.content(); + console.log(html); + + await browser.close(); +})(); + diff --git a/package.json b/package.json new file mode 100644 index 0000000..34a0b42 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "puppeteer": "^23.11.1" + } +} -- cgit v1.2.3