这是我的代码:
Main.js
:
const request = require('request')
const cheerio = require('cheerio')
const jsonFile = require('jsonfile')
request("https://nrldc.in", function(error, response, html){
//console.log(response)
if(!error && response.statusCode == 200){
const $ = cheerio.load(html)
}
let h1 = $('div.textwidget:nth-child(1)> p:nth-child(2) > strong:nth-child(1)> span:nth-child(1)').text()
console.log(h1)
这是我的HTML文件的一部分:
<div class="textwidget">
<p></p>
<p style="text-align: left; font-size:24px;font-weight:bold;">NR Grid Frequency:
<strong><span style="font-size: 23px;color:red;">49.82</span></strong>
</p>
</div>
我想在49.82
标签中获取数据<span>
。但是没有类名或ID。我该怎么办?
我的目标是从网站上抓取。我正在使用Cheerio和Node.js。这是我的代码:Main.js:const request = require('request')const cheerio = require('cheerio')const jsonFile = require('...