mtg-price/index.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-01-08 13:23:25 +00:00
const { Builder, By, Key, until } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
2019-01-08 14:07:41 +00:00
const firefox = require('selenium-webdriver/firefox')
2019-01-08 15:00:18 +00:00
const config = require('./config')
2019-01-08 13:23:25 +00:00
const setsUrl = 'https://www.echomtg.com/sets/'
const setsClass = '.main.marketAnalysis.sets'
2019-01-08 15:00:18 +00:00
if (!/^(firefox|chrome)$/i.test(config.browser)) {
console.log('browser type not support')
process.exit(1)
}
2019-01-08 13:23:25 +00:00
;(async () => {
2019-01-08 15:00:18 +00:00
let opts = null
let driver = null
if (/firefox/i.test(config.browser)) {
opts = new firefox.Options()
opts.headless()
if (config.firefox_path.length > 0) {
opts.setBinary(config.firefox_path)
}
driver = await new Builder().forBrowser('firefox').setFirefoxOptions(opts).build()
} else if (/chrome/i.test(config.browser)) {
opts = new chrome.Options()
opts.headless()
if (config.chrome_path.length > 0) {
opts.setChromeBinaryPath(config.chrome_path)
}
driver = await new Builder().forBrowser('chrome').setChromeOptions(opts).build()
} else {
console.log('browser type not support')
}
// driver = await new Builder().forBrowser('firefox').setFirefoxOptions(ffOpts).build()
2019-01-08 13:23:25 +00:00
await driver.get(setsUrl)
let el = await driver.findElement(By.css(setsClass))
2019-01-08 14:07:41 +00:00
let sets = await el.findElements(By.css('h4>a'))
for (let it of sets) {
console.log(await it.getText())
}
//console.log(sets)
2019-01-08 13:23:25 +00:00
})().catch(console.warn)