(public)
-
Requires node.js
-
Run it by setting the
sid
as shown in /ras/NodeでPrivateなscrapboxの情報を取得する -
It currently works at a basic level
- The JavaScript code is written in a rough manner for now
- There are mixed uses of
$
and$x
which will be fixed later
-
It seems that pages opened in another browser while the import is running will not be overwritten?
- No, that’s not the case.
-
Does it matter if the browser is closed when it says “Importing Pages…“?
- No, that’s not the case either.
-
Copying pages that didn’t exist originally seems to work fine every time, but overwriting existing pages doesn’t always work properly.
- The conditions for this are unknown…
.js
const puppeteer = require('puppeteer');
const sid = "YOUR SID";
const project = "experiment-blu3mo";
(async () => {
const url = new URL(`https://scrapbox.io/projects/${project}/settings/page-data`);
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
defaultViewport: {width: 800, height: 1024}
});
const page = await browser.newPage();
await page.setCookie({name: 'connect.sid', value: sid, domain: 'scrapbox.io'});
await page.goto(url.toString());
await page.waitFor(1000);
const inputUploadHandle = await page.$('input[name="import-file"]');
inputUploadHandle.uploadFile("FILE.json");
await page.waitFor(1000);
const importSubmitButton = await page.$x("//button[contains(., 'Import Pages')]");
await importSubmitButton[0].click();
await browser.close();
})()
- I’m trying this out (tkgshn)
- Where did this
FILE.json
come from? - I exported it as JSON from a random project, renamed the file, and placed it in the same directory. When I ran
$ node example.js
, it worked for now. But I don’t know how it’s being retrieved in Importing to Scrapbox with Puppeteer. - (blu3mo) This assumes manual export.
- If you want to automate the export, you can do it with Calling Scrapbox’s export API with GAS.
- (blu3mo) By combining Importing to Scrapbox with Puppeteer and Calling Scrapbox’s export API with GAS, you can create scrapbox-duplicator.
- Where did this