Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

How to scrape any website and build an API using cheerio.js

--

Press enter or click to view image in full size
Image by https://undraw.co

I was looking for GitHub trending projects API, but unfortunately, GitHub does not provide an official API for it. I decided to build github-trending-api myself using cheerio.js.

In this article, I will share with you my experience using cheerio.js, writing tests, and pushing new changes to the API server Now automatically.

1. cheerio.js

There are a lot of tools when you want to scrape web using Javascript. Cheerio.js is one of them. The syntax is very much like old jQuery style, if you are familiar with jQuery, you should be able to familiar with cheerio.js very quickly.

For example, if you want to get all the project titles from GitHub trending page, you could use below code snippet.

The above code snippet will print out all the repositories titles as an array.

--

--