feat: Adds Serper.dev integration

closes #138
This commit is contained in:
towfiqi 2024-02-09 00:43:28 +06:00
parent f04b10cf6b
commit b4ad69baaa
2 changed files with 37 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import spaceserp from './services/spaceserp';
import proxy from './services/proxy';
import searchapi from './services/searchapi';
import valueSerp from './services/valueserp';
import serper from './services/serper';
export default [
scrapingRobot,
@ -16,4 +17,5 @@ export default [
proxy,
searchapi,
valueSerp,
serper,
];

View File

@ -0,0 +1,35 @@
interface SerperResult {
title: string,
link: string,
position: number,
}
const serper:ScraperSettings = {
id: 'serper',
name: 'Serper.dev',
website: 'serper.dev',
allowsCity: true,
scrapeURL: (keyword, settings, countryData) => {
const country = keyword.country || 'US';
const lang = countryData[country][2];
return `https://google.serper.dev/search?q=${encodeURI(keyword.keyword)}&gl=${country}&hl=${lang}&num=100&apiKey=${settings.scaping_api}`;
},
resultObjectKey: 'organic',
serpExtractor: (content) => {
const extractedResult = [];
const results: SerperResult[] = (typeof content === 'string') ? JSON.parse(content) : content as SerperResult[];
for (const { link, title, position } of results) {
if (title && link) {
extractedResult.push({
title,
url: link,
position,
});
}
}
return extractedResult;
},
};
export default serper;