const { Builder, By, until } = require('selenium-webdriver'); /** * 指定したURLをChromeで開き、ログインID・パスワードを入力してLoginボタンをクリックし、 * その後id="UpdateCommand"のボタンをクリックして10秒待機する * @param {string} url 開くWEBサイトのURL * @param {string} loginId ログインID * @param {string} password パスワード */ const baseUrl = 'https://nextoffice.next-hd.co.jp/pleasanter'; //const baseUrl = 'https://neo999.next-hd.net/pleasanter'; async function openAndClickUpdateCommand(url, loginId, password) { let driver = await new Builder().forBrowser('chrome').build(); try { await driver.get(url); // ログインID・パスワード入力 await driver.wait(until.elementLocated(By.id('Users_LoginId')), 10000); await driver.findElement(By.id('Users_LoginId')).sendKeys(loginId); await driver.wait(until.elementLocated(By.id('Users_Password')), 10000); await driver.findElement(By.id('Users_Password')).sendKeys(password); // Loginボタンをクリック await driver.wait(until.elementLocated(By.id('Login')), 10000); await driver.findElement(By.id('Login')).click(); await driver.sleep(5000); // id="UpdateCommand"のボタンが表示されるまで待機(最大10秒) const button = await driver.wait( until.elementLocated(By.id('UpdateCommand')), 10000 ); await button.click(); await driver.sleep(10000); } finally { await driver.quit(); } } async function getPleasanterData(nendo) { const tableId = '214737'; // サブテーブルのIDを指定 const apiKey = '6504c8a807677a3a576e10327f3c19876c55736ee45d4a845796b9e7f5e087bfd4bd0d8184863da8cf1733ca635111432ab334aea59102b06a96ee6d2c05190d'; const pleasanterUrl = baseUrl + '/api/items/' + tableId + '/get' // 年度をClassZの条件にセット const jsonBody = { 'ApiVersion': 1.1, 'ApiKey': apiKey, 'View': { 'ColumnSorterHash': { 'ClassB': 'asc' }, 'ColumnFilterHash': { 'ClassZ': `["${nendo}"]` }, } } const pleasanterRes = await fetch(pleasanterUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(jsonBody) }); const resData = await pleasanterRes.json(); //console.log(resData); for (const item of resData.Response.Data) { let resultId = item.ResultId.toString(); const url = baseUrl + '/items/' + resultId + '/edit'; const loginId = 'SystemUser'; // 実際のログインIDに変更 const password = "pfS+Zx&\\'hFaz0w|X&V1"; // 実際のパスワードに変更 await openAndClickUpdateCommand(url, loginId, password) .then(() => console.log('完了')) .catch(err => console.error('エラー:', err)); } } function main() { // コマンドライン引数から年度を取得 const args = process.argv.slice(2); const nendo = args[0] || '2025'; // デフォルトは2025 getPleasanterData(nendo); } main();