| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
Paige Gorry Kate Dameron
For this project you'll need to set up a Node.js server. We used Express.js but you can use whatever you want!
run
npm add -D node-html-parser superagent
const request = require('superagent');
const { parse } = require('node-html-parser');
const scraper = () => {
return request
.get([your url here])
.then(res => res.text)
.then(parse)
.then(console.log);
};
scraper();
module.exports = { scraper };
Open up your dev tools and inspect the elements that hold the data you need to scrape. In our case, the first thing we needed to do was grab each h3 header with the class mw-headline. Here's a screenshot to see what we started with this:
const titlesList = html => html
.querySelectorAll('h3 .mw-headline')
.map(node => node.rawText);
const scraper = () => {
return request
.get('url')
.then(res => res.text)
.then(parse)
.then(titlesList)
.then(console.log);
};
run node scraper.js again
At this point you should be able to see the data and start to make decisions about how to grab different elements, run some clean up functions and start to piece it all together to match your db schema
| Back | FazBrowse Home | New Git URL |