S
S
Savege_John2018-08-26 22:21:10
JavaScript
Savege_John, 2018-08-26 22:21:10

How to parse photos in Node.js?

I would like to know how to do this, or rather through which module, because my task is as follows:
I need to parse photos from this rss feed: " https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss ", but how to do that? I would be very happy if you could help me figure this out.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
l1l1l1, 2018-08-26
@l1l1l1

Use one of the many npm packages that make it possible to send http requests, such as request , and from the response collect all the links with a regular expression.

P
priority12, 2018-09-08
@priority12

Install modules:
1. https://github.com/expressjs/express
2. https://github.com/request/request
3. https://github.com/cheeriojs/cheerio
Code for your task:

var express = require('express');
var app = express();
var request = require('request');
var cheerio = require('cheerio');
var port = 8080;

var url = "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss";

var content = [];

request(url, function(err, res, body) {
  var $ = cheerio.load(body);
    $('enclosure').each(function(i, elem) {
    	content.push($(this).attr('url'));
   });
    for (var i = 0; i<content.length; i++) {     
      console.log(content[i]);   
    }
});

app.listen(port);

E
Evgeny Vorobyov, 2018-08-27
@lokki00003

Why do you need node.js ?
$file=file_get_contents('link to rss');
preg_match_all('#enclosure url="(.*)"#isU',$file,$match);
$cou=count($match[1]);
for($i=0;$i<$cou;$i++)
{ #these
are pictures
print_r($match[1][$i]);
}
done;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question