|
const app = require("express")(); |
|
|
|
let chrome = {}; |
|
let puppeteer; |
|
|
|
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) { |
|
chrome = require("chrome-aws-lambda"); |
|
puppeteer = require("puppeteer-core"); |
|
} else { |
|
puppeteer = require("puppeteer"); |
|
} |
|
|
|
app.get("/api", async (req, res) => { |
|
let options = {}; |
|
|
|
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) { |
|
options = { |
|
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"], |
|
defaultViewport: chrome.defaultViewport, |
|
executablePath: await chrome.executablePath, |
|
headless: true, |
|
ignoreHTTPSErrors: true, |
|
}; |
|
} |
|
|
|
try { |
|
let browser = await puppeteer.launch(options); |
|
|
|
let page = await browser.newPage(); |
|
await page.goto("https://liaobots.work/"); |
|
await page.click('label.button'); |
|
await page.waitForNavigation(); |
|
await page.waitForTimeout(2000); |
|
|
|
|
|
const value = await page.evaluate(() => { |
|
|
|
return localStorage.getItem('authCode'); |
|
}); |
|
|
|
res.send(value); |
|
} catch (err) { |
|
console.error(err); |
|
return null; |
|
} |
|
}); |
|
|
|
app.listen(process.env.PORT || 3000, () => { |
|
console.log("Server started"); |
|
}); |
|
|
|
module.exports = app; |