bid-tool/scrape-data-keyword/models/scrap-model.js

36 lines
974 B
JavaScript

export class ScrapModel {
constructor({ keywords, search_url, scrap_config_id, page, web_bid }) {
this.keywords = keywords;
this.search_url = search_url;
this.scrap_config_id = scrap_config_id;
this.results = {};
this.page = page;
this.web_bid = web_bid;
}
buildUrlWithKey(rawUrl, keyword) {
return rawUrl.replaceAll("{{keyword}}", keyword);
}
extractUrls() {
const keywordList = this.keywords.split(", ");
if (keywordList.length <= 0) return [];
return keywordList.map((keyword) => ({
url: this.buildUrlWithKey(this.search_url, keyword),
keyword,
}));
}
filterItemByKeyword(keyword, data) {
return data.filter((item) =>
item.name.toLowerCase().includes(keyword.toLowerCase())
);
}
// Phần này bạn cần truyền từ bên ngoài khi khởi tạo hoặc kế thừa class:
action = async (page) => {};
getInfoItems = (data) => [];
getItemsInHtml = async (data) => [];
}