Skip to content

Instantly share code, notes, and snippets.

@FujiHaruka
Created September 2, 2017 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FujiHaruka/84e074dccea3001ea794697f97617225 to your computer and use it in GitHub Desktop.
Save FujiHaruka/84e074dccea3001ea794697f97617225 to your computer and use it in GitHub Desktop.
Headless Chrome example to search amazon
const Chromy = require('chromy')
const word = 'JavaScript'
const chromy = new Chromy()
chromy.chain()
.goto('https://www.amazon.co.jp/')
.select('select#searchDropdownBox', 'search-alias=stripbooks')
.insert('input#twotabsearchtextbox', word)
.click('input[type=submit]', {waitLoadEvent: true})
// 検索結果ページ
.evaluate(() => {
const resultList = document.querySelector('#s-results-list-atf')
const titles = resultList.querySelectorAll('h2')
return Array.from(titles).map(
(title) => title.innerText
)
})
.result((r) => console.log(r))
.end()
.catch((e) => {
console.log()
})
.then(() => chromy.close())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment