Reputation: 269
i hope you care. I have troble when scraping data in another website. this my case, when i see in page source data is empty, but when i see in inspect element i see the data. if you not understand see these image, first in inspect element and second in view page source
this is my code
const request = require('request');
const cheerio = require('cheerio');
const url = "https://pikobar.jabarprov.go.id/"
request(url, (error, response, html) => {
let $ = cheerio.load(html);
$('b').each((i, element) => {
let omg = $(element).text();
console.log(omg);
});
});
i want text 388
Upvotes: 0
Views: 725
Reputation: 16150
If you see the document source (Ctrl+U), this element is really empty. That's because it's being filled afterwards, by a Ajax request. If you go to Network tab and reload, you will see all files being transferred. The url you are looking for is https://covid19-public.digitalservice.id/api/v1/rekapitulasi/jabar?level=prov which have the data you are looking for.
fetch("https://covid19-public.digitalservice.id/api/v1/rekapitulasi/jabar?level=prov")
.then(r => r.json())
.then(d => console.log(d.data.content.positif))
Upvotes: 1