How to use simply dev community recent posts as feed?

dev-feeds-scrap

Dev is a community of software/web developers getting together to assist each other. We can’t be active all time over community so don’t miss creative post, You can get all post under single page over your website or your blog.

Let’s start with node.js

I will show you to scrap dev.to latest post including their title and relevant content. You will be required to include Axios npm package to send http request over dev.to. This package will extract html of latest post, Afterward you need to load html and have to scrap html content, For which you must install cheerio npm package.

Http request to extract html using axios

axios.get(url)
.then(response => {
getData(response.data);
})
.catch(error=>{
console.log(error);
})

Load and scrap html using cheerio

let getData = html => {
  data = [];
  const $ = cheerio.load(html);
  $('a.crayons-story__hidden-navigation-link').each((i, elem) => {
    data.push({
      title : $(elem).text(),
      link:$(elem).attr('href')
    });

  }); 

Here i just scrap title and their href , Whatever you want to scrap of a post , you may access using class name or id. Store scrap data into an array and send to view files for render.

<div class="jumbotron">
        <h1>Dev.to Feeds</h1>
        <ul>
	    <% data.forEach(function(elem) { %>
	        <li>
	            <strong><a href="https://dev.to/<%= elem.link %>"><%= elem.title %></a></strong>

	        </li>
	    <% }); %>
	</ul>
    </div>

You may get code from here

Author: Shantun Parmar

Comments are closed.