This commit is contained in:
Jay
2019-01-08 23:00:18 +08:00
parent fcc53ee3e7
commit 51cfd59350
3 changed files with 67 additions and 4 deletions
+35
View File
@@ -0,0 +1,35 @@
const { Builder, By, Key, until } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const firefox = require('selenium-webdriver/firefox')
const config = require('../config')
const setsUrl = 'https://www.echomtg.com/sets/'
const setsClass = '.main.marketAnalysis.sets'
module.exports.getDriver = async () => {
if (!/^(firefox|chrome)$/i.test(config.browser)) {
throw new Error('browser type not support')
}
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 {
throw new Error('browser type not support')
}
return driver
}