-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscrap.js
More file actions
87 lines (71 loc) · 1.95 KB
/
Copy pathscrap.js
File metadata and controls
87 lines (71 loc) · 1.95 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const cheerio = require('cheerio');
const Sequelize = require('sequelize');
const request = require('request-promise')
const input = require('input');
require('dotenv').config();
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'data.db',
logging: false
});
const Hadis = sequelize.define('Hadis', {
nomor: Sequelize.INTEGER,
perawi: Sequelize.STRING,
arabic: Sequelize.TEXT,
terjemahan: Sequelize.TEXT,
riwayat: Sequelize.STRING
}, {
timestamps: false
});
/*
- bukhari: 7008 *
- muslim: 5362 *
- abudaud: 4590 *
- tirmidzi: 3891 *
- nasai: 5662 *
- ibnumajah: 4332 *
- malik: 1594 *
- ahmad: 15070 *
- darimi: 3367 *
*/
(async function() {
// sync database
await sequelize.sync();
// await Hadis.destroy({ truncate: true });
const p = await input.text('Hadits:');
let page = parseInt(await input.text('From page:'));
console.log('Scrapping hadis:', p);
// scrapping over page
while(true) {
try {
const url = `https://hadits.in/${p}/${page}`;
const data = await request({
url: url,
proxy: process.env.ROTATING_PROXY
});
if(data) {
console.log('[', p, '] Halaman:', page);
const $ = cheerio.load(data);
// stop scrapping
if($('title').text() === 'Ensiklopedi Hadits - Kitab 9 Imam') {
console.log('Total:', page - 1);
break;
}
// get info
const arabic = $('#arabic_container').text();
const arti = $('#terjemah_container').text();
const hr = $('[property="og:title"]').attr('content');
Hadis.create({
nomor: page,
perawi: p,
arabic: arabic,
terjemahan: arti,
riwayat: hr
});
page++;
}
} catch(err) {
console.log(err.message);
}
}
})();