2023-03-13 13:42:43 +01:00
|
|
|
import { config } from '../utils.js';
|
|
|
|
|
import makeDriver from './requestDriver.js';
|
|
|
|
|
import Xray from 'x-ray';
|
2018-01-20 20:23:27 +01:00
|
|
|
class Scraper {
|
|
|
|
|
constructor() {
|
|
|
|
|
const filters = {
|
|
|
|
|
removeNewline: this._removeNewline,
|
|
|
|
|
trim: this._trim,
|
2021-01-21 16:09:23 +01:00
|
|
|
int: this._int,
|
2018-01-20 20:23:27 +01:00
|
|
|
};
|
2021-05-11 11:25:14 +02:00
|
|
|
const headers = {
|
|
|
|
|
'User-Agent':
|
|
|
|
|
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36',
|
|
|
|
|
};
|
|
|
|
|
if (config.scrapingAnt != null && config.scrapingAnt.apiKey != null) {
|
|
|
|
|
headers['x-api-key'] = config.scrapingAnt.apiKey;
|
|
|
|
|
}
|
|
|
|
|
const driver = makeDriver(headers);
|
2018-01-20 20:23:27 +01:00
|
|
|
const xray = Xray({ filters });
|
|
|
|
|
xray.driver(driver);
|
|
|
|
|
this.xray = xray;
|
|
|
|
|
}
|
|
|
|
|
get x() {
|
|
|
|
|
return this.xray;
|
|
|
|
|
}
|
|
|
|
|
_removeNewline(value) {
|
|
|
|
|
return typeof value === 'string' ? value.replace(/\\n/g, '') : value;
|
|
|
|
|
}
|
|
|
|
|
_trim(value) {
|
|
|
|
|
return typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : value;
|
|
|
|
|
}
|
|
|
|
|
_int(value) {
|
|
|
|
|
return typeof value === 'string' ? parseInt(value, 10) : value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-13 13:42:43 +01:00
|
|
|
export default new Scraper().x;
|