Created
September 2, 2017 06:14
-
-
Save FujiHaruka/84e074dccea3001ea794697f97617225 to your computer and use it in GitHub Desktop.
Headless Chrome example to search amazon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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