I have an allure report webpage that provides a dashboard with a percentage on it. I have to create a completely separate webpage which should show that percentage.
How can I pull that div from that page?
Here's the picture of a div
Asked
Active
Viewed 498 times
0

OshiniRB
- 578
- 1
- 7
- 21

Maksym Iliev
- 47
- 1
- 5
-
I assume the dashboard requires a login? You will probably have to use [puppeteer](https://github.com/puppeteer/puppeteer#getting-started) for this. – Oct 14 '21 at 17:25
-
@chris-g Thanks for the heads up. Currently login is not required but will be setup in the future. – Maksym Iliev Oct 14 '21 at 17:38
-
You can do authentication with fetch (https://stackoverflow.com/questions/43842793/basic-authentication-with-fetch), but depending on how your app handles auth, it might be better to use puppeteer as suggested by @Chris G – ᴓᴓᴓ Oct 14 '21 at 17:42
1 Answers
0
Fetch it, and then parse it until you have the contents of that div.
For fetch, something simple like (polyfill fetch or use axios instead if using nodejs):
fetch('https://jsonplaceholder.typicode.com').then(function (response) {
// The API call was successful!
return response.text();
}).then(function (data) {
// This is the HTML text from our response
console.log(data);
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
});
And then for parsing, answers like this will be helpful:

ᴓᴓᴓ
- 1,178
- 1
- 7
- 18
-
This will only work if the other website has CORS enabled for its HTML files and also populates the dashboard HTML server-side. I wish it were that simple but it probably isn't. – Oct 14 '21 at 17:47
-
That's true, but assuming you control the report server, why not try a simple solution first? – ᴓᴓᴓ Oct 14 '21 at 17:58
-
If you control the server, you don't have to scrape it, you can just retrieve the value directly. And if not, my approach would be to check the console of the dashboard website and see if it fetches data, then skip the entire HTML part. – Oct 14 '21 at 17:59
-