summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README.md13
-rw-r--r--curl.js28
-rw-r--r--package.json5
4 files changed, 47 insertions, 0 deletions
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"
+ }
+}