通过Cheerio检索自动完整价值
有一个网站可以结合韩国动词 https://www.verbix.com/languages/languages/korean 。我想做的是在输入中键入某些内容,然后获取出现建议的文本。
这是我的代码:
app.get("/conjugation", (req, res) => {
axios("https://www.verbix.com/languages/korean")
.then((response) => {
const htmlData = response.data;
const $ = cheerio.load(htmlData);
//Input Element
const input = $("#auto-complete-edit");
//Pass the value to it
input.attr("value", "먹어요");
//Get the selected element
const select = $(".selected");
select
.map((i, child) => {
//Get the 'a' element inner text
return $(child).find("a").text();
})
.get();
console.log(select);
})
.catch((err) => console.log(err));
});
并且控制台显示了这一点
LoadedCheerio {
length: 0,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': Document {
parent: null,
prev: null,
next: null,
startIndex: null,
endIndex: null,
children: [Array],
type: 'root',
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *1]
},
prevObject: <ref *2> LoadedCheerio {
'0': Document {
parent: null,
prev: null,
next: null,
startIndex: null,
endIndex: null,
children: [Array],
type: 'root',
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *2]
}
}
there's this website that conjugates korean verbs https://www.verbix.com/languages/korean. What i wanna do is type something in the input and then get the text of the suggestion that appears.
That blue part is the 'a' element's text
This is my code:
app.get("/conjugation", (req, res) => {
axios("https://www.verbix.com/languages/korean")
.then((response) => {
const htmlData = response.data;
const $ = cheerio.load(htmlData);
//Input Element
const input = $("#auto-complete-edit");
//Pass the value to it
input.attr("value", "먹어요");
//Get the selected element
const select = $(".selected");
select
.map((i, child) => {
//Get the 'a' element inner text
return $(child).find("a").text();
})
.get();
console.log(select);
})
.catch((err) => console.log(err));
});
And the console shows this
LoadedCheerio {
length: 0,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': Document {
parent: null,
prev: null,
next: null,
startIndex: null,
endIndex: null,
children: [Array],
type: 'root',
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *1]
},
prevObject: <ref *2> LoadedCheerio {
'0': Document {
parent: null,
prev: null,
next: null,
startIndex: null,
endIndex: null,
children: [Array],
type: 'root',
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *2]
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论