added eslint, some cleanup and fetch in english

This commit is contained in:
2020-05-24 21:28:05 +03:00
parent 8c5fba8788
commit 1b22ac4ceb
8 changed files with 1312 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
import { JSDOM } from "jsdom";
import Car from "../model/Car";
import { JSDOM } from 'jsdom';
import Car from '../model/Car';
import Selectors from '../util/Selectors';
class Scraper {
@@ -9,7 +9,7 @@ class Scraper {
setContent(text) {
const parsedContent = new JSDOM(text).window.document;
if (parsedContent.querySelector(Selectors.properties.main.container) === null) {
throw Error('No data was received. Cookie is probably expired.')
throw Error('No data was received. Cookie is probably expired.');
}
this.document = parsedContent;
}
@@ -20,7 +20,7 @@ class Scraper {
scrapeMainProperties() {
const {
main: selector
main: selector,
} = Selectors.properties;
this.document
.querySelector(selector.container)
@@ -34,25 +34,22 @@ class Scraper {
data = value[1].innerHTML;
}
this.car[value[0].innerHTML] = data;
})
});
}
scrapeBasicProperties() {
if (!this.document) {
throw Error('No data to scrape.');
}
const properties = this.document.querySelector('#content');
const {
properties: selector
properties: selector,
} = Selectors;
const plate = this.getTextBySelector(selector.plate);
const carName = this.getTextBySelector(selector.name);
const vin = this.getTextBySelector(selector.vin);
console.log(plate, carName, vin);
this.car = new Car(plate, carName, vin.substring(5));
return this.car;
}
}
export default Scraper;