cheerio 相关问题

专为服务器设计的核心jQuery的快速,灵活和精益实现。 https://github.com/cheeriojs/cheerio

仅保留其中包含文本的元素并删除所有其他元素

我正在尝试使用 puppeteer 和 Cheerio 抓取一个网站。我已经获得了我想要使用 puppeteer 抓取的页面的 html。我已将该 html 加载到 Cheerio 中。 异步函数 run() { 常量

回答 1 投票 0

如何使用cheerio库在元素每次出现时运行inquirer.prompt?

我目前正在开发控制台应用程序,它允许用户更改 HTML 文件内的值。我正在使用 Cheerio 库在 HTML 文件中查找每次出现的类调用...

回答 1 投票 0

使用 Cheerio 抓取雅虎财经汇总表

我正在尝试从雅虎财经汇总表中抓取“1y Target Est, 1,140.21”,如红色标记。 我尝试了这段代码,但没有得到任何数据。 检查标签,我看到“1,1140.21&q...

回答 1 投票 0

使用cheerio从表中抓取所有行

我正在尝试从网页 https://www.barchart.com/stocks/quotes/aapl/performance 上的价格表现表中抓取所有行 这是折线图下方的表格。该表没有任何 id...

回答 1 投票 0

用cheerio解析表行

我尝试使用cheerio 从表中提取一些数据。 这是一个简化版本: 常量表=` 我尝试使用cheerio 从表中提取一些数据。 这是一个简化版本: const table = ` <table> <tr> <td></td> <td class="with-link"><a href="www.foo.bar"></a></td> </tr> </table> ` const row = `<td><a href="www.foo.bar"></a></td>` class Scraper { htmlToDom(html) { return cheerio.load(html) } findHref(row) { return row('a').attr('href') } } const scraper = new Scraper() const cheerioRow = scraper.htmlToDom(row) console.log(scraper.findHref(cheerioRow)) const cheerioTable = scraper.htmlToDom(table) cheerioTable('tr').each(function() { //console.log(this) let td = this.find('td.with-link') console.log(scraper.findHref(td)) }) <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="https://wzrd.in/standalone/cheerio@latest"></script> <title>JS Bin</title> </head> <body> </body> </html> Scraper类有两种方法,一种可以加载html(字符串)并返回一个cheerio对象。另一个需要一个 (cheerio) td 对象,并从中返回 href。 第一个控制台日志显示 findHref 按预期工作。然后我加载整个表,循环遍历它的行(在本例中只有一个)。在 each 循环 this 内部应该是一个 roe (tr) 对象。我尝试找到正确的单元格(带有“with-link”类),并将其传递给findHref。 但我越来越 “类型错误:this.find 不是函数 以防万一,这里是 JsBin:https://jsbin.com/vakofapiro/edit?js,console 代替这个使用cheerioTable。 let td = cheerioTable(this).find('td.with-link').html(); 它会给你 td 的内部 html,它是一个 href。

回答 1 投票 0

使用 Cheerio 绘制雅虎财经汇总表

我正在尝试从雅虎财经汇总表中抓取“1y Target Est, 1,140.21”,如红色标记。 我尝试了这段代码,但没有得到任何数据。 检查标签,我看到“1,1140.21&q...

回答 1 投票 0

Cheerio 无法读取元素的“href”属性,即使它存在于源代码中

我正在尝试为PS5游戏的二手网站创建一个爬虫。为此,我使用 Cheerio 来解析结果列表。在某些情况下它能够正确读取 URL,在其他情况下它

回答 1 投票 0

无法利用应用程序脚本中的 CSS 选择器获取下一页链接

我试图使用应用程序脚本中的CSS选择器从此网页抓取下一页链接,但结果总是未定义,即使我定义的选择器是正确的。 函数 fetchInform...

回答 1 投票 0

如何抓取已禁用 DevTools 的网站

如何抓取已禁用 Chrome DevTools 的网站? 使用 Puppeteer,我尝试使用特定航空公司各自的 CSS 选择器获取其出发和到达时间,但是......

回答 1 投票 0

使用 Cheerio 抓取许多网站

我正在使用cheerio 抓取大约800 个网站,只是为了获取网站标题。我遇到的第一个问题是,有时我会收到一条错误消息,显示“我们遇到了错误:错误:s...

回答 2 投票 0

使用cheerio抓取动态网站[重复]

我在从网站抓取数据时遇到了麻烦。我无法获取 table 的标签 ,然后我无法获取标签 和 的内容文本。我使用cheerio来爬取数据。

回答 1 投票 0

在实时服务器上使用 axios.get 时出现 404 响应

我正在学习使用 JavaScript 进行网页抓取,在尝试将一个简单的网页登录到控制台时,我收到了一个奇怪的 404 错误: 无法加载资源:服务器响应状态为 4...

回答 1 投票 0

在实时服务器上使用 axios.get 时出现 404 响应

我正在学习使用 JavaScript 进行网页抓取,在尝试将一个简单的网页登录到控制台时,我收到了一个奇怪的 404 错误: 无法加载资源:服务器响应状态为 4...

回答 1 投票 0

href 值我使用 Cheerio

我正在尝试使用cheerio进行抓取。不过我遇到了一个小问题。我在客户端获得的所有 href 值都以“/url?q=”开头。例如这样: '/url?q=https://www.nimh.ni...

回答 1 投票 0

使用node.js从div中检索文本

我目前正在尝试编写一个抓取工具,它将使用node.js从Facebook帖子内的div中获取所有“p”标签 页面上的每个帖子都位于 div 中,并且都具有此类别...

回答 2 投票 0

无法从 Facebook 广告的元标记中抓取图像 url - Axios Cheerio

感谢您的光临。 我正在尝试使用 Axios 和 Cheerio 从 Facebook 广告 URL 中抓取 og:image 元标记的值。我有一个函数可以在 dep 的上下文中调用...

回答 1 投票 0

使用cheerio从表中抓取所有行

我正在运行以下代码来抓取数据。但是,该代码仅抓取第一个元素。 const Cheerio = require('cheerio') const jsonframe = require('jsonframe-cheerio') const 得 = 要求('...

回答 2 投票 0

用cheerio刮取所有元素

我正在运行以下代码来抓取数据。但是,该代码仅抓取第一个元素。 const Cheerio = require('cheerio') const jsonframe = require('jsonframe-cheerio') const 得 = 要求('...

回答 2 投票 0

Cheerio 获取类的多个匹配项中的第一个元素

我有这个 HTML: ... 我有这个 HTML: <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong> 208,00 Euro </strong> </p> </div> 第二部分如下所示: <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>1.978,00 Euro</strong> </p> </div> 类“flex__col--md-2 flex__col--xs-4 col...”和类“u-text-white”可以在html中找到两次。我想从第一个条目“208,00 Euro”中选择值。 var parsedHTML = $.load(body); console.log("the value"); 有人可以帮我使用cheerio 将 208 欧元存入控制台日志吗? 您应该能够像这样访问数据。 var firstEl = parsedHTML .find('.flex__col--md-2.flex__col--xs-4') .first() .find('.u-text-white'); var data = firstEl.find('strong').text(); 改进现有答案,您可以使用自然的 CSS 链接,而无需多次 .find() 调用: const cheerio = require("cheerio"); // ^1.0.0-rc.12 const html = `<div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>208,00 Euro</strong> </p> </div> <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>1.978,00 Euro</strong> </p> </div>`; const $ = cheerio.load(html); const text = $(".flex__col--md-2.flex__col--xs-4 p.u-text-white") .first() .text() .trim(); console.log(text); // => 208,00 Euro 这里答案的关键部分是.first()。 .last() 和 .nth(0) 是 .first() 上有用的变体函数。 其他选项包括: const text = $(".flex__col--md-2.flex__col--xs-4 p.u-text-white:nth(0)") .text() .trim(); 和 const text = $(".flex__col--md-2.flex__col--xs-4 p.u-text-white:first") .text() .trim();

回答 2 投票 0

从 dom 获取课程 -->cheerio

我有这个 HTML: ... 我有这个 HTML: <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong> 208,00 Euro </strong> </p> </div> 第二部分如下所示: <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>1.978,00 Euro</strong> </p> </div> 类“flex__col--md-2 flex__col--xs-4 col...”和类“u-text-white”可以在html中找到两次。我想从第一个条目“208,00 Euro”中选择值。 var parsedHTML = $.load(body); console.log("the value"); 有人可以帮我使用cheerio 将 208 欧元存入控制台日志吗? 您应该能够像这样访问数据。 var firstEl = parsedHTML .find('.flex__col--md-2.flex__col--xs-4') .first() .find('.u-text-white'); var data = firstEl.find('strong').text(); 改进现有答案,您可以使用自然 CSS 链接,而无需多次 .find() 调用: const cheerio = require("cheerio"); // ^1.0.0-rc.12 const html = `<div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>208,00 Euro</strong> </p> </div> <div class="flex__col--md-2 flex__col--xs-4 color-box color-box--orange color-box--no-pad text-center"> <p class="u-text-white"> <strong>1.978,00 Euro</strong> </p> </div>`; const $ = cheerio.load(html); const text = $(".flex__col--md-2.flex__col--xs-4 p.u-text-white") .first() .text() .trim(); console.log(text); // => 208,00 Euro 这里答案的关键部分是.first()。

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.