fix: google name parsing

This commit is contained in:
Artemy 2023-08-18 11:38:30 +03:00
parent 08a89190ed
commit 82a7fb96e6

View File

@ -8,13 +8,13 @@ export default async function google(
const googleAnchors = [ const googleAnchors = [
...window.document.querySelectorAll("a[jsname=ACyKwe]"), ...window.document.querySelectorAll("a[jsname=ACyKwe]"),
] as HTMLAnchorElement[]; ] as HTMLAnchorElement[];
const googleNames = [...window.document.querySelectorAll(".VuuXrf")];
const results = googleAnchors const results = googleAnchors
.map((a: HTMLAnchorElement, i: number): GoogleProps => { .map((a: HTMLAnchorElement): GoogleProps => {
const parsedHref = new URL(new URL(a.href).searchParams.get("url")!);
return { return {
href: a.href!, href: a.href!,
siteName: googleNames[i].textContent!, siteName: parsedHref.hostname,
heading: a.childNodes[1]?.textContent, heading: a.childNodes[1]?.textContent,
}; };
}) })
@ -26,12 +26,6 @@ export default async function google(
); );
} }
if (!googleNames) {
throw new EngineParseError(
"Failed to find names in search result [google]"
);
}
const convertToFormat = (result: GoogleProps, isHtml: boolean) => { const convertToFormat = (result: GoogleProps, isHtml: boolean) => {
return isHtml return isHtml
? `<p><a href="${result.href}">${result.siteName} - ${result.heading}</p>` ? `<p><a href="${result.href}">${result.siteName} - ${result.heading}</p>`