Merge pull request #23 from TxtDot/Google-fix-all-results

fix: google search parsing
This commit is contained in:
Andrey 2023-08-17 18:13:00 +04:00 committed by GitHub
commit e2ba8c8e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,9 +5,7 @@ import { EngineParseError } from "../errors/main";
export default async function google(
window: DOMWindow
): Promise<IHandlerOutput> {
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
? `<p><a href="${anchor.href}">${heading.innerHTML}</p>`
: `${heading.innerHTML} > ${anchor.href}`;