Skip to content

Commit

Permalink
HasData scraper added
Browse files Browse the repository at this point in the history
  • Loading branch information
valka465 authored Mar 28, 2024
1 parent 3fc1024 commit 79fc6b9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scrapers/services/hasdata.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 79fc6b9

Please sign in to comment.