R
R
rick142019-02-12 11:34:21
JavaScript
rick14, 2019-02-12 11:34:21

How to parse meta tags in node.js?

Good afternoon. It is not possible to pick up the description tag and writing to json does not go as it should.
Can you suggest how to do it right?

var needle = require("needle");
var cheerio = require("cheerio");
var async = require("async");
var request = require('request');
var resolve = require('url').resolve;
var fs = require('fs');
var url = "https://toster.ru";
var results = [];
var q = async.queue(function(url){
        needle.get(url,function(err,res){
        if(err) throw(err);
        var $ = cheerio.load(res.body);
        
              console.log($('description').text());
               console.log($('title').text());
            results.push({
                title: $('title').text(),
                description:$('description').text(),
                href: url                
            });
       
    });
}, 10); 

  q.drain = function(){
    fs.writeFileSync('./data.json', JSON.stringify(results, "", 4));
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-02-12
@rick14

description is not a tag, it's the name of a meta tag. this is how it should be
$('meta[name="description"]').attr('content')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question