npm i puppeteer
index.js
const puppeteer = require('puppeteer');
async function translateText(text, sl, tl) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
`http://translate.google.com/?sl=${sl}&tl=${tl}&text=${text}&op=translate`
);
const bodyHandle = await page.$('.ryNqvb');
const html = await page.evaluate((body) => body.innerHTML, bodyHandle);
console.log('html', html);
await browser.close();
return html;
}
translateText('Hello, world!', 'auto', 'zh-CN');
node inde.js