DEV Community

Cover image for Don't want miss recent post on dev, Make feed on your web
Shantun Parmar
Shantun Parmar

Posted on

Don't want miss recent post on dev, Make feed on your web

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);
})
Enter fullscreen mode Exit fullscreen mode

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')
    });

  }); 
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Preview

Coodigdessign.com

You may get code from here

Thanks for reading!

Originally published at my blog coodingdessign.com

Top comments (0)