Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .actor/actor.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"title": "Overview",
"description": "An view showing just basic properties for simplicity.",
"transformation": {
"flatten": ["metadata"],
"flatten": ["metadata", "searchResult"],
"fields": [
"metadata.url",
"metadata.title",
"searchResult.resultType",
"markdown"
]
},
Expand All @@ -34,6 +35,10 @@
"label": "Page title",
"format": "text"
},
"searchResult.resultType": {
"label": "Result type",
"format": "text"
},
"text": {
"label": "Extracted Markdown",
"format": "text"
Expand All @@ -49,6 +54,7 @@
"fields": [
"searchResult.title",
"searchResult.description",
"searchResult.resultType",
"searchResult.url"
]
},
Expand All @@ -63,6 +69,10 @@
"label": "Title",
"format": "text"
},
"searchResult.resultType": {
"label": "Result type",
"format": "text"
},
"searchResult.url": {
"label": "URL",
"format": "text"
Expand Down
16 changes: 10 additions & 6 deletions src/google-search/google-extractors-urls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CheerioAPI } from 'cheerio';
import type { Element } from 'domhandler';

import type { OrganicResult } from '../types.js';
import type { OrganicResult, SearchResultType } from '../types.js';

/**
* Deduplicates search results based on their title and URL (source @apify/google-search).
Expand Down Expand Up @@ -64,7 +64,7 @@ const areTheResultsSuggestions = ($: CheerioAPI) => {
/**
* Extracts organic search results from the given Cheerio instance (source: @apify/google-search).
*/
export const scrapeOrganicResults = ($: CheerioAPI) => {
export const scrapeOrganicResults = ($: CheerioAPI): OrganicResult[] => {
const resultSelectors2023January = [
'.hlcw0c', // Top result with site links
'.g.Ww4FFb', // General search results
Expand All @@ -75,10 +75,14 @@ export const scrapeOrganicResults = ($: CheerioAPI) => {
'.sATSHe', // another new selector in March 2025
];

const searchResults = extractResultsFromSelectors($, resultSelectors2023January);
const deduplicatedResults = deduplicateResults(searchResults);
let resultType: SearchResultType = 'ORGANIC';
if (areTheResultsSuggestions($)) {
return [];
resultType = 'SUGGESTED';
}

const searchResults = extractResultsFromSelectors($, resultSelectors2023January);
return deduplicateResults(searchResults);
return deduplicatedResults.map((result) => ({
...result,
resultType,
}));
};
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ export type Input = {
scrapingTool: ScrapingTool;
};

export type SearchResultType = 'ORGANIC' | 'SUGGESTED';

export type OrganicResult = {
description?: string;
title?: string;
rank?: number;
url?: string;
resultType?: SearchResultType;
};

export interface TimeMeasure {
Expand Down