@@ -24,14 +24,15 @@ export const deduplicateResults = <T extends { title?: string; url?: string }>(r
24
24
* Extracts search results from the given selectors (source: @apify/google-search).
25
25
*/
26
26
const extractResultsFromSelectors = ( $ : CheerioAPI , selectors : string [ ] ) => {
27
- const searchResults = [ ] ;
27
+ const searchResults : OrganicResult [ ] = [ ] ;
28
28
const selector = selectors . join ( ', ' ) ;
29
29
for ( const resultEl of $ ( selector ) ) {
30
- searchResults . push (
31
- ...$ ( resultEl )
32
- . map ( ( _i , el ) => parseResult ( $ , el as Element ) )
33
- . toArray ( ) ,
34
- ) ;
30
+ const results = $ ( resultEl ) . map ( ( _i , el ) => parseResult ( $ , el as Element ) ) . toArray ( ) ;
31
+ for ( const result of results ) {
32
+ if ( result . title && result . url ) {
33
+ searchResults . push ( result ) ;
34
+ }
35
+ }
35
36
}
36
37
return searchResults ;
37
38
} ;
@@ -59,7 +60,7 @@ export const scrapeOrganicResults = ($: CheerioAPI) => {
59
60
const resultSelectors2023January = [
60
61
'.hlcw0c' , // Top result with site links
61
62
'.g.Ww4FFb' , // General search results
62
- '.MjjYud .g ' , // General catch all. Used for one main + one nested from the same site. Added in Jun 2023, not very good selector
63
+ '.MjjYud' , // General search results 2025 March, this includes also images so we need to add a check that results has both title and url
63
64
'.g .tF2Cxc>.yuRUbf' , // old search selector 2021 January
64
65
'.g [data-header-feature="0"]' , // old search selector 2022 January
65
66
'.g .rc' , // very old selector
0 commit comments