-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportFileToSubturtle.js
More file actions
36 lines (29 loc) · 1.22 KB
/
Copy pathimportFileToSubturtle.js
File metadata and controls
36 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const puppeteer = require("puppeteer");
const fs = require("fs");
// Read the JSON file
const vocabularies = JSON.parse(fs.readFileSync("vocabularies.json", "utf8"));
const websiteAddress =
"https://www.subturtle.app/dashboard/bundles/6630e5fcda2347001cd296ba";
async function launch() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(websiteAddress, {
waitUntil: "networkidle2",
});
return { page, browser };
}
(async () => {
const { page, browser } = await launch();
await page.click("#submit-button");
for (let vocab of vocabularies) {
// Select the input fields and fill them with the vocabulary data
await page.type("#english-input", vocab.word); // Replace with the actual selector for the English word input field
await page.type("#meaning-input", vocab.meaning); // Replace with the actual selector for the meaning input field
// Submit the form or click the add button
await page.click("#submit-button"); // Replace with the actual selector for the submit button
// Wait for any necessary delay or page reload
await page.waitForTimeout(1000); // Adjust the delay as needed
}
// Close the browser
await browser.close();
})();