Created
June 27, 2019 14:34
-
-
Save Tetsuya-Minase/8b5a5938569390867bd775646fd83f76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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