Rwsult / server.js
understanding's picture
Update server.js
6c7ed0c verified
raw
history blame
1.44 kB
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 with headers to mimic browser
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);
// Updated selectors based on common patterns
const result = {
name: $('span#lblName').text().trim() || $('td:contains("Name") + td').text().trim(),
regno: $('span#lblRegNo').text().trim() || regno,
sgpa: $('span#lblSGPA').text().trim() || $('td:contains("SGPA") + td').text().trim()
};
console.log('Scraped Result:', result);
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}`);
});