Comments (3)
so sorry I let this slip! Thank you for the advice.. it worked well.. here's kinda what I did (modified, not tested);
const axios = require('axios');
let Parser = require('rss-parser');
let parser = new Parser();
module.exports = async function parseRss(params) {
const { lastModified, url } = params; // from db record of RSS parse
let headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0',
'If-Modified-Since': lastModified
};
let result = await axios({
url,
headers,
method: 'get',
})
.then(result => result)
.catch(err => ({ error: '304/404', url }));
if (result.error) return result.error;
let xml = result.data;
let rssParsed;
try {
rssParsed = await parser.parseString(xml);
} catch (err) {
// debug('error in `rss-parser`');
return false;
}
rssParsed.lastModified = result.headers['last-modified'];
rssParsed.etag = result.headers['etag'];
if (rssParsed.error) return rssParsed.error;
return rssParsed;
};
from rss-parser.
Hi Carl,
I would suggest issuing the HTTP request yourself, then passing the result to parseString
.
You could also modify the code to add the response headers to the returned object. Or there might be a clever way to handle the conditional GET inside the library. Happy to accept a PR if you go that route.
from rss-parser.
Keeping this open - we should implement an ifModifiedSince
option
from rss-parser.
Related Issues (20)
- Add `parseBuffer` method HOT 1
- Removing http & https web request library dependencies HOT 2
- Get first 3 items separately
- Parser throws on 304s
- Not able to get data from CDATA coming in description tag in RSS HOT 1
- Cointelegraph RSS not being parsed HOT 2
- `HPE_INVALID_HEADER_TOKEN` error due to `Invalid header value char`
- Explain custom fields in TypeScript sample. HOT 1
- Convert item.title with html tags to html
- ReadMe.Remove non-working Typescript code that is very confusing.
- add build-related files and dirs to .npmignore file
- Socket remains open after a timeout HOT 1
- How can I limit the data from the rss on NextJS? HOT 1
- Error: 500 Cannot read properties of undefined (reading 'prototype') HOT 2
- Getting breaking change errors for reactjs project HOT 8
- Uncaught TypeError: Cannot read properties of undefined (reading 'protoype') HOT 3
- CVE-2023-0842 high-severity vulnerability in current version of dependency xml2js HOT 1
- Broken on webpack 5 HOT 3
- I am not able to fetch few RSS urls like BBC and Times Of India HOT 1
- ParseURL fails with ERR_ADDRESS_UNREACHABLE in Android Emulator using Ionic/Capacitor in Android HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rss-parser.