File size: 1,330 Bytes
7385ed3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const app = express();
const PORT = 7860;

app.get('/fetch-regno-:regno', async (req, res) => {
    try {
        const { regno } = req.params;
        const url = `https://results.beup.ac.in/ResultsBTech1stSem2023_B2023Pub.aspx?Sem=I&RegNo=${regno}`;
        
        // Fetch the page
        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/91.0.4472.124 Safari/537.36'
            }
        });

        // Parse HTML
        const $ = cheerio.load(response.data);
        
        // Extract data - adjust selectors based on actual page structure
        const result = {
            name: $('#lblName').text().trim(),
            regno: $('#lblRegNo').text().trim(),
            sgpa: $('#lblSGPA').text().trim(),
            // Add more fields as needed
        };

        console.log('Scraped Result:', result); // Log to terminal
        res.json(result);
    } catch (error) {
        console.error('Error:', error.message);
        res.status(500).json({ error: 'Failed to fetch result' });
    }
});

app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});