From 79fc6b935c59ffdde9269086b56acf45f82cfa00 Mon Sep 17 00:00:00 2001 From: valka465 <46899675+valka465@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:57:15 +0300 Subject: [PATCH] HasData scraper added --- scrapers/services/hasdata.ts | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scrapers/services/hasdata.ts diff --git a/scrapers/services/hasdata.ts b/scrapers/services/hasdata.ts new file mode 100644 index 0000000..353e718 --- /dev/null +++ b/scrapers/services/hasdata.ts @@ -0,0 +1,45 @@ +import countries from '../../utils/countries'; + +interface HasDataResult { + title: string, + link: string, + position: number, +} + +const hasdata:ScraperSettings = { + id: 'hasdata', + name: 'HasData', + website: 'hasdata.com', + allowsCity: true, + headers: (keyword, settings) => { + return { + 'Content-Type': 'application/json', + 'x-api-key': settings.scaping_api, + }; + }, + scrapeURL: (keyword, settings) => { + const country = keyword.country || 'US'; + const countryName = countries[country][0]; + const location = keyword.city && countryName ? `&location=${encodeURI(`${keyword.city},${countryName}`)}` : ''; + return `https://api.scrape-it.cloud/scrape/google/serp?q=${encodeURI(keyword.keyword)}${location}&num=100&gl=${country.toLowerCase()}&deviceType=${keyword.device}`; + }, + resultObjectKey: 'organicResults', + + serpExtractor: (content) => { + const extractedResult = []; + const results: HasDataResult[] = (typeof content === 'string') ? JSON.parse(content) : content as HasDataResult[]; + + for (const { link, title, position } of results) { + if (title && link) { + extractedResult.push({ + title, + url: link, + position, + }); + } + } + return extractedResult; + }, +}; + +export default hasdata;