hhaammzzaa2 hhaammzzaa2 - 1 year ago 79
Node.js Question

How do I manipulate data on a webpage from node.js

I'm kind of new to node.js and Javascript so forgive me if the question is poorly worded.

I'm using cheeriojs to scrape data from a site. I'm running the js file that scrapes the data in the command line and it outputs the data I want, but I want to be able to have access to this data on a webpage, where I can put it into a table. (or anything else I want for that matter). How exactly do I do this?

Thank you

Answer Source

Learn how to use express.

Serve the page to a browser, by reading the file and serving it with an express endpoint, or to curl or something. ie curl localhost:8080/your-endpoint

Using the browser manipulate the page inside of the browsers dev tools.

Figure out how to get the current DOM as an html string.

Figure out how to use the fetch API inside of a browser such as fetch(url, {method: 'POST'}).then(...)

After manipulating the DOM with the browsers dev tools.

POST the results back to express on the nodejs server.

Save the req.body or req.data or req.params to a file.

Side notes: - figure out what a callback is, figure out how promises work - do some research on express middleware - look into setInterval, setTimeout


Other options, use a text editor, use sed, grep, awk, bash, or something else that doesn't require serving files to a browser?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download