update
This commit is contained in:
parent
fcc53ee3e7
commit
51cfd59350
6
config.js
Normal file
6
config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const env = process.env
|
||||||
|
module.exports = {
|
||||||
|
browser: env.BROWSER || '',
|
||||||
|
firefox_path: env.FIREFOX_PATH || '',
|
||||||
|
chrome_path: env.CHROME_PATH || ''
|
||||||
|
}
|
30
index.js
30
index.js
@ -1,16 +1,38 @@
|
|||||||
const { Builder, By, Key, until } = require('selenium-webdriver')
|
const { Builder, By, Key, until } = require('selenium-webdriver')
|
||||||
const chrome = require('selenium-webdriver/chrome')
|
const chrome = require('selenium-webdriver/chrome')
|
||||||
const firefox = require('selenium-webdriver/firefox')
|
const firefox = require('selenium-webdriver/firefox')
|
||||||
|
const config = require('./config')
|
||||||
|
|
||||||
const setsUrl = 'https://www.echomtg.com/sets/'
|
const setsUrl = 'https://www.echomtg.com/sets/'
|
||||||
|
|
||||||
const setsClass = '.main.marketAnalysis.sets'
|
const setsClass = '.main.marketAnalysis.sets'
|
||||||
|
|
||||||
|
if (!/^(firefox|chrome)$/i.test(config.browser)) {
|
||||||
|
console.log('browser type not support')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
let ffOpts = new firefox.Options()
|
let opts = null
|
||||||
ffOpts.headless()
|
let driver = null
|
||||||
ffOpts.setBinary('/root/apps/firefox/firefox')
|
if (/firefox/i.test(config.browser)) {
|
||||||
let driver = await new Builder().forBrowser('firefox').setFirefoxOptions(ffOpts).build()
|
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()
|
||||||
await driver.get(setsUrl)
|
await driver.get(setsUrl)
|
||||||
let el = await driver.findElement(By.css(setsClass))
|
let el = await driver.findElement(By.css(setsClass))
|
||||||
let sets = await el.findElements(By.css('h4>a'))
|
let sets = await el.findElements(By.css('h4>a'))
|
||||||
|
35
libs/driver.js
Normal file
35
libs/driver.js
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user