Skip to content

Commit

Permalink
perf: more advanced googleling
Browse files Browse the repository at this point in the history
  • Loading branch information
mxvsh committed Jul 16, 2021
1 parent 9ec912e commit a54c3cd
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/modules/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ const Answer = async (ctx, params?) => {
},
})
.then(({ data }) => {
const classes = ["kno-rdesc", "DjWnwf", "Z0LcW", "hgKElc"];
const classes = ["kno-rdesc", "DjWnwf", "Z0LcW", "hgKElc", "vXQmIe"];

const $ = cheerio.load(data);
for (let _class of classes) {
let text = $(`.${_class}`).text();
if (text) {
if (text.startsWith("Description")) {
text = text.replace(/^Description/g, "");
const calcAns = $("input[jsname='fPLMtf']");
if (calcAns) answer = `<b>${String(calcAns.val())}</b>`;
else
for (let _class of classes) {
let text = $(`.${_class}`).text();
if (text) {
if (text.startsWith("Description")) {
text = text.replace(/^Description/g, "");
}
answer = `<b>${text}</b>`;
break;
}
answer = `<b>${text}</b>`;
break;
}
}
})
.catch((err) => {
answer = "Not found.";
Expand Down

0 comments on commit a54c3cd

Please sign in to comment.