[英]Getting div text inside nested table td with Cheerio
Using Cheerio and axios, I am trying to get the text "Version" and "1.7.0" from the divs inside nested tds in a table from a vscode marketplace page 使用Cheerio和axios,我试图从vscode市场页面的表中的嵌套tds中的div中获取div的文本“ Version”和“ 1.7.0”
I have tried this and a bunch of other ways to pinpoint the div text at the bottom but I'm not sure that I'm addressing it correctly. 我已经尝试过这种方法以及其他方法来确定div文本底部的位置,但是我不确定是否正确地解决了它。 I am unsure where to start to get the nested elements inside the table, and I am pretty confused. 我不确定从哪里开始在表中获取嵌套元素,我很困惑。 Any help on the surely simple problem is appreciated. 感谢您提供有关肯定简单的问题的帮助。
const cheerio = require('cheerio');
const axios = require('axios');
const url = "https://marketplace.visualstudio.com/items?itemName=bloumbs.borders-dark"
axios.get(url).then((response) => {
const $ = cheerio.load(response.data)
// With this I get no response:
$('.ux-table-metadata > tbody > tr > td > div').each(() => {
console.log($(this).text());
});
// And with this method, it return "null"
let version = $('.ux-table-metadata tbody tr td div').html($.versionText)
console.log(version)
})
This is the section of html I'm working with: 这是我正在使用的html部分:
<div class="ux-section-other">
<h3 class="itemdetails-section-header right">More Info</h3>
<div>
<table class="ux-table-metadata">
<tbody>
<tr>
<td>
<div>Version</div>
</td>
<td>
<div>1.7.0</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
$(".ux-table-metadata > tbody > tr > td").each(function() {
console.log($(this).find("div").html());
});
or 要么
$(".ux-table-metadata > tbody > tr > td").each(function() {
console.log($(this).children().html());
});
tested with jquery 用jQuery测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.