Answer the question
In order to leave comments, you need to log in
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
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.
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);
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 questionAsk a Question
731 491 924 answers to any question