Spaces:
Sleeping
Sleeping
Create server.js
Browse files
server.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require('express');
|
2 |
+
const axios = require('axios');
|
3 |
+
const cheerio = require('cheerio');
|
4 |
+
const app = express();
|
5 |
+
const PORT = 7860;
|
6 |
+
|
7 |
+
app.get('/fetch-regno-:regno', async (req, res) => {
|
8 |
+
try {
|
9 |
+
const { regno } = req.params;
|
10 |
+
const url = `https://results.beup.ac.in/ResultsBTech1stSem2023_B2023Pub.aspx?Sem=I&RegNo=${regno}`;
|
11 |
+
|
12 |
+
// Fetch the page
|
13 |
+
const response = await axios.get(url, {
|
14 |
+
headers: {
|
15 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
16 |
+
}
|
17 |
+
});
|
18 |
+
|
19 |
+
// Parse HTML
|
20 |
+
const $ = cheerio.load(response.data);
|
21 |
+
|
22 |
+
// Extract data - adjust selectors based on actual page structure
|
23 |
+
const result = {
|
24 |
+
name: $('#lblName').text().trim(),
|
25 |
+
regno: $('#lblRegNo').text().trim(),
|
26 |
+
sgpa: $('#lblSGPA').text().trim(),
|
27 |
+
// Add more fields as needed
|
28 |
+
};
|
29 |
+
|
30 |
+
console.log('Scraped Result:', result); // Log to terminal
|
31 |
+
res.json(result);
|
32 |
+
} catch (error) {
|
33 |
+
console.error('Error:', error.message);
|
34 |
+
res.status(500).json({ error: 'Failed to fetch result' });
|
35 |
+
}
|
36 |
+
});
|
37 |
+
|
38 |
+
app.listen(PORT, () => {
|
39 |
+
console.log(`Server running on port ${PORT}`);
|
40 |
+
});
|