Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
@@ -9,26 +9,26 @@ app.get('/fetch-regno-:regno', async (req, res) => {
|
|
9 |
const { regno } = req.params;
|
10 |
const url = `https://results.beup.ac.in/ResultsBTech1stSem2023_B2023Pub.aspx?Sem=I&RegNo=${regno}`;
|
11 |
|
12 |
-
// Fetch the page
|
13 |
const response = await axios.get(url, {
|
14 |
headers: {
|
15 |
-
'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'
|
|
|
16 |
}
|
17 |
});
|
18 |
|
19 |
-
// Parse HTML
|
20 |
const $ = cheerio.load(response.data);
|
21 |
|
22 |
-
//
|
23 |
const result = {
|
24 |
-
name: $('#lblName').text().trim(),
|
25 |
-
regno: $('#lblRegNo').text().trim(),
|
26 |
-
sgpa: $('#lblSGPA').text().trim()
|
27 |
-
// Add more fields as needed
|
28 |
};
|
29 |
|
30 |
-
console.log('Scraped Result:', result);
|
31 |
res.json(result);
|
|
|
32 |
} catch (error) {
|
33 |
console.error('Error:', error.message);
|
34 |
res.status(500).json({ error: 'Failed to fetch result' });
|
|
|
9 |
const { regno } = req.params;
|
10 |
const url = `https://results.beup.ac.in/ResultsBTech1stSem2023_B2023Pub.aspx?Sem=I&RegNo=${regno}`;
|
11 |
|
12 |
+
// Fetch the page with headers to mimic browser
|
13 |
const response = await axios.get(url, {
|
14 |
headers: {
|
15 |
+
'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',
|
16 |
+
'Referer': 'https://results.beup.ac.in/'
|
17 |
}
|
18 |
});
|
19 |
|
|
|
20 |
const $ = cheerio.load(response.data);
|
21 |
|
22 |
+
// Updated selectors based on common patterns
|
23 |
const result = {
|
24 |
+
name: $('span#lblName').text().trim() || $('td:contains("Name") + td').text().trim(),
|
25 |
+
regno: $('span#lblRegNo').text().trim() || regno,
|
26 |
+
sgpa: $('span#lblSGPA').text().trim() || $('td:contains("SGPA") + td').text().trim()
|
|
|
27 |
};
|
28 |
|
29 |
+
console.log('Scraped Result:', result);
|
30 |
res.json(result);
|
31 |
+
|
32 |
} catch (error) {
|
33 |
console.error('Error:', error.message);
|
34 |
res.status(500).json({ error: 'Failed to fetch result' });
|