| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Think we missed something? Have additional resources that you want to share? Feel free to submit a PR and contribute to this project!
This tutorial walks you through creating your own API by data-scraping using a Node.js application with an Express server and NOSQL database (MongoDB). Feel free to substitute your own language, server, and db of choice.
If you are a beginner, please check out our beginner.md file for resource links.
What you need to get started:
run npm add -D node-html-parser superagent (these are dev dependencies hence the -D)
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 |