From f460cd596685c07c271f532e0878dd9c33c50ca7 Mon Sep 17 00:00:00 2001 From: Artemy Date: Thu, 17 Aug 2023 17:03:08 +0300 Subject: [PATCH] fix: google search parsing --- src/handlers/google.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/handlers/google.ts b/src/handlers/google.ts index d6bb780..c3c3d7d 100644 --- a/src/handlers/google.ts +++ b/src/handlers/google.ts @@ -5,9 +5,7 @@ import { EngineParseError } from "../errors/main"; export default async function google( window: DOMWindow ): Promise { - const googleAnchors = window.document.querySelectorAll( - "#rso > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)" - ); + const googleAnchors = window.document.querySelectorAll("a[jsname=ACyKwe]"); if (!googleAnchors) { throw new EngineParseError( @@ -19,6 +17,9 @@ export default async function google( const convertToFormat = (result: Element, isHtml: boolean) => { const anchor = result as HTMLAnchorElement; const heading = anchor.childNodes[1] as HTMLHeadingElement; + if (!heading) { + return ""; + } return isHtml ? `

${heading.innerHTML}

` : `${heading.innerHTML} > ${anchor.href}`;