Spaces:
Sleeping
Sleeping
File size: 1,746 Bytes
7385ed3 26bacb1 7385ed3 26bacb1 7385ed3 6c7ed0c 7385ed3 26bacb1 7385ed3 26bacb1 7385ed3 26bacb1 7385ed3 26bacb1 7385ed3 26bacb1 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const app = express();
const PORT = 7860;
// Middleware to log requests
app.use((req, res, next) => {
console.log(`[${new Date().toISOString()}] ${req.method} ${req.path}`);
next();
});
app.get('/fetch-regno-:regno', async (req, res) => {
const { regno } = req.params;
console.log(`Fetching result for RegNo: ${regno}`);
try {
const url = `https://results.beup.ac.in/ResultsBTech1stSem2023_B2023Pub.aspx?Sem=I&RegNo=${regno}`;
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',
'Referer': 'https://results.beup.ac.in/'
}
});
const $ = cheerio.load(response.data);
// Clean up the data
const cleanText = (selector) => {
return $(selector).text()
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.trim();
};
const result = {
name: cleanText('#lblName'),
regno: regno,
sgpa: cleanText('#lblSGPA').replace(/Cur\. CGPA.*/, '') // Remove unwanted text
};
res.json(result);
} catch (error) {
console.error(`Error fetching ${regno}:`, error.message);
res.status(500).json({
error: 'Failed to fetch result',
regno: regno
});
}
});
app.listen(PORT, () => {
console.log(`==== Application Startup at ${new Date().toISOString()} ====`);
console.log(`Server running on port ${PORT}`);
}); |