-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
45 lines (36 loc) · 1.48 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const axios = require('axios');
const cheerio = require('cheerio');
// URL to scrape
const url = 'https://sirup.lkpp.go.id/sirup/home/detailPaketSwakelolaPublic2017?idPaket=37150386';
async function scrapeData() {
try {
// Set headers to mimic a browser request
const response = await axios.get(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36',
'Accept': 'text/html',
'Referer': 'https://sirup.lkpp.go.id/'
}
});
// Load the HTML content into cheerio
const $ = cheerio.load(response.data);
// Example: Scrape the package name
const packageName = $('h3').text().trim(); // You can refine this if needed
console.log('Package Name:', packageName);
// Scraping the "Total Dana" value from the table
const totalDanaRow = $('tr').filter(function() {
return $(this).text().includes('Total');
});
// Now find the <span> element containing the 'rupiah' class in this row
const totalDana = totalDanaRow.find('span.rupiah').text().trim();
if (totalDana) {
console.log('Total Dana:', totalDana);
} else {
console.log('Total Dana: Data not found');
}
} catch (error) {
console.error('Error scraping data:', error);
}
}
// Run the scrape function
scrapeData();