mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
parent
f04b10cf6b
commit
b4ad69baaa
@ -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,
|
||||
];
|
||||
|
35
scrapers/services/serper.ts
Normal file
35
scrapers/services/serper.ts
Normal 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;
|
Loading…
Reference in New Issue
Block a user