Update scrapper.js
Browse files- scrapper.js +35 -1
scrapper.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
const axios = require('axios')
|
|
|
|
|
2 |
const {GptModelOld} = require('./models');
|
3 |
|
4 |
const OpenaiRes = async (prompt) => {
|
@@ -32,4 +34,36 @@ const OpenaiRes = async (prompt) => {
|
|
32 |
}
|
33 |
};
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
const axios = require('axios')
|
2 |
+
const cheerio = require('cheerio');
|
3 |
+
|
4 |
const {GptModelOld} = require('./models');
|
5 |
|
6 |
const OpenaiRes = async (prompt) => {
|
|
|
34 |
}
|
35 |
};
|
36 |
|
37 |
+
async function tebakgambar() {
|
38 |
+
try {
|
39 |
+
const url = "https://jawabantebakgambar.net/all-answers/";
|
40 |
+
const response = await axios.get(url);
|
41 |
+
const $ = cheerio.load(response.data);
|
42 |
+
|
43 |
+
const randomNum = Math.floor(Math.random() * (2836 - 2 + 1)) + 2; // Random between 2 and 2836
|
44 |
+
const selectedItem = $(`#images > li:nth-child(${randomNum}) > a`);
|
45 |
+
|
46 |
+
if (selectedItem.length > 0) {
|
47 |
+
const img = 'https://jawabantebakgambar.net' + selectedItem.find('img').attr('data-src');
|
48 |
+
const jwb = selectedItem.find('img').attr('alt');
|
49 |
+
|
50 |
+
const result = {
|
51 |
+
message: "By Randydev",
|
52 |
+
image: img,
|
53 |
+
jawaban: jwb
|
54 |
+
};
|
55 |
+
|
56 |
+
return result;
|
57 |
+
} else {
|
58 |
+
throw new Error("Selected item not found.");
|
59 |
+
}
|
60 |
+
} catch (error) {
|
61 |
+
console.error(error);
|
62 |
+
return null;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
module.exports = {
|
67 |
+
OpenaiRes,
|
68 |
+
tebakgambar
|
69 |
+
};
|