Skip to content

Instantly share code, notes, and snippets.

@Tetsuya-Minase
Created June 27, 2019 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tetsuya-Minase/8b5a5938569390867bd775646fd83f76 to your computer and use it in GitHub Desktop.
Save Tetsuya-Minase/8b5a5938569390867bd775646fd83f76 to your computer and use it in GitHub Desktop.
import { HttpRequest } from '../../../infrastructure/http-request';
import { JSDOM } from 'jsdom';
import { RequestResponse } from '../../model/request-response';
import { ScrapingService } from '../scraping-service';
import { inject, injectable } from 'inversify';
import 'reflect-metadata';
import { TYPES } from '../../../inversify.types';
@injectable()
export class ScrapingServiceImpl implements ScrapingService {
private request: HttpRequest;
constructor(@inject(TYPES.HttpRequest) httpRequest: HttpRequest) {
this.request = httpRequest;
}
public async fetchDomData(url: string): Promise<JSDOM> {
const response: RequestResponse = await this.request.get(url).catch(e => {
console.error('service error:', e);
throw e;
});
return new JSDOM(response['body']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment