fix: google search parsing
This commit is contained in:
parent
232bde1cd8
commit
f460cd5966
@ -5,9 +5,7 @@ import { EngineParseError } from "../errors/main";
|
|||||||
export default async function google(
|
export default async function google(
|
||||||
window: DOMWindow
|
window: DOMWindow
|
||||||
): Promise<IHandlerOutput> {
|
): Promise<IHandlerOutput> {
|
||||||
const googleAnchors = window.document.querySelectorAll(
|
const googleAnchors = window.document.querySelectorAll("a[jsname=ACyKwe]");
|
||||||
"#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)"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!googleAnchors) {
|
if (!googleAnchors) {
|
||||||
throw new EngineParseError(
|
throw new EngineParseError(
|
||||||
@ -19,6 +17,9 @@ export default async function google(
|
|||||||
const convertToFormat = (result: Element, isHtml: boolean) => {
|
const convertToFormat = (result: Element, isHtml: boolean) => {
|
||||||
const anchor = result as HTMLAnchorElement;
|
const anchor = result as HTMLAnchorElement;
|
||||||
const heading = anchor.childNodes[1] as HTMLHeadingElement;
|
const heading = anchor.childNodes[1] as HTMLHeadingElement;
|
||||||
|
if (!heading) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return isHtml
|
return isHtml
|
||||||
? `<p><a href="${anchor.href}">${heading.innerHTML}</p>`
|
? `<p><a href="${anchor.href}">${heading.innerHTML}</p>`
|
||||||
: `${heading.innerHTML} > ${anchor.href}`;
|
: `${heading.innerHTML} > ${anchor.href}`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user