ts-scraper
v1.0.3
Published
Scarp links present in the website recursively
Downloads
5
Readme
ts-scraper
Web scraper written on TypeScript
It is a webscraper which can be extendable to do multiple tasks on scraped content. It propogates through the links it finds in the page. It makes use of ts-jobrunner
library to run everything in terms of jobs.
Installation
npm install --save ts-scraper
Core API
CoreScraper(abstract)
- protected init(): void
- protected canFetchUrl(url): boolean
- protected createJob(link): CoreJob
- protected onFetchComplete(link, response): void
- public start(): void
PageScraper(abstract)
- public async start()
- public abstract parse(jquery: JQuery): any;
ScrapeJob(abstract)
- public run()
- abstract createPageScraper(url: string): PageScraper
- There are three components in this library
CoreScraper
,PageScraper
andScrapeJob
. ScrapeJob
extends CoreJob fromts-jobrunner
library. Its object exposes functioncreatePageScraper(url)
which createsPageScraper
which actally mines/scrapes the page.PageScraper
exposes a functionparse($)
which takes jQuery object. You can mine the page as your wish and return the parsed responseCoreScraper
is the main object which runs the scraping process. Its object has to have above mentioned functions.init()
all initiations can be put herecanFetchUrl(url)
should tell whether to fetch the found linkurl
createJob(link)
should return aCoreJob
type job, which then be queuedonFetchComplete(link, response)
will get triggered when aScrapeJob
job is completed ie., when aPageScraper
is done. You can have code which handles the response returned byPageScraper
herestart()
will actually the scraping process (start()
onJobRunner
)
Example
Please find example usage in src/test/test-scraper
folder
Suggestions and contributions are open. Happy coding :)