Rwsult / server.js
understanding's picture
Create server.js
7385ed3 verified
raw
history blame
1.33 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
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}`);
});