通过Cheerio检索自动完整价值

发布于 2025-02-12 04:24:39 字数 2042 浏览 0 评论 0原文

有一个网站可以结合韩国动词 https://www.verbix.com/languages/languages/korean 。我想做的是在输入中键入某些内容,然后获取出现建议的文本。

蓝色部分是'A'元素的文本

这是我的代码:

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.
enter image description here

That blue part is the 'a' element's text
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文