Spaces:
Sleeping
Sleeping
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}`); | |
}); |