问题描述
我想用cheerio刮一张桌子。我有:
async function fetchHTML(url) {
const {data} = await axios.get(url)
return cheerio.load(data)
}
try {
const $ = await fetchHTML(URL);
const tableSelector = "div:nth-child(4) ..... table.table.table-striped.table-bordered.table-condensed";
const StateCodetablehtml = $(tableSelector).html();
console.log(StateCodetablehtml)
我可以看到这是预期的 html:
<tbody><tr>
<th class="table-number">Sqft</th>
<th class="table-number">Eff Front</th>
<th class="table-number">Eff Depth</th>
<th class="table-number">Market Value</th>
<th class="table-number">Prod. Value</th>
</tr>
<tr>
<td class="table-number"></td>
<td class="table-number">
</td>
<td class="table-number">
</td>
<td class="table-number">$40,500</td>
<td class="table-number">$0</td>
</tr>
</tbody>
const y = await helpers.tablehtmlToRowObjects(StateCodetablehtml);
在新函数中:
async function tablehtmlToRowObjects(html) {
const $ = cheerio.load(html);
var head1 = await $('tbody > tr > th').html();
await console.log(head1);
产生空值。我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)