xcraper
v0.0.4
Published
Based on cheerio and native fetch enable to "Xcrape" data from html content
Downloads
13
Readme
Xcraper
Based on cheerio and native fetch enable to "Xcrape" data from html content
Types
type Schema = {
type: "text" | "number" | "array" | "object";
attribute?: string;
selector?: string;
child?: { [key: string]: Schema };
selector?: string;
children?: Schema;
};Usage
import { Xcraper } from "./src";
Xcraper.fetch(url, [options]).extract(schema);
url: string;
options: RequestInit;
schema: Schema;Sample
import { Xcraper } from "./src";
Xcraper.fetch(
"https://www.foxnews.com/entertainment/tom-cruise-ana-de-armas-fuel-romance-rumors-stepping-out-london-again"
).extract({
type: "object",
child: {
title: {
type: "text",
selector: ".headline.speakable",
},
description: {
type: "text",
selector: ".sub-headline.speakable",
},
articleDate: {
type: "text",
selector: ".article-date time",
},
content: {
type: "array",
selector: ".article-content .article-body p",
children: {
type: "text",
},
},
images: {
type: "array",
selector: ".article-content .article-body img",
children: {
type: "text",
attribute: "src",
},
},
},
});
// OUTPUT
// {
// title: string;
// description: string;
// articleDate: string;
// content: string[];
// images: string[];
// }