4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

puppeteer でターミナルから google 翻訳

Posted at

鶴田謙二さんイラストの puppeteer 入門(ヴェネチア冒険団團/三崎 薫/小原 亮一/酒井 一成 著)
面白かったです。

参考にして試しによく使ってる google 翻訳をコマンドラインから叩けるスクリプト作ってみました。

const puppeteer = require('puppeteer')
const URL = 'https://translate.google.co.jp/?hl=ja'
;(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    slowMo: 50
  })
  const page = await browser.newPage()
  await page.setViewport({ width: 1500, height: 800 })
  await page.goto(URL)
  if (process.argv.length > 2) {
    process.argv.splice(0,2)
    word = process.argv.join(" ")
    console.log(word)
    await page.click('#sugg-item-en')
    await page.type('textarea#source', word)
    await page.click("input#gt-submit[type='submit']")
  }
  // browser.close()
})()

例えば、

$ node googleTrans.js I am a boy.

スクリーンショット 2018-11-11 23.10.06.png

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?