Generate an RSS feed using the Scrapy framework.
Table of Contents
Installation
Install
scrapy-rss-exporterusingpip:pip install scrapy-rss-exporteror using
setuptools:python setup.py install
Usage
Feed Items
The most convenient way to use the exporter is to return the objects of
RssItem class from your spiders. This class derives from
scrapy.Item, so it will work with other exporters as well.
You will need to set the following keys:
from scrapy_rss_exporter.items import RssItem, Enclosure
rss_item = RssItem()
rss_item['title'] = 'Item title'
rss_item['link'] = 'Item url'
rss_item['guid'] = 'Item ID'
rss_item['description'] = 'Item Description'
rss_item['pub_date'] = None
rss_item['enclosure'] = [Enclosure(url=img, type='image/jpeg')]
The pub_date field should contain a date in the
RFC882
format. If you use None, the system will insert the current date
in the appropriate format. The enclosure field is optional and should
contain a (possibly empty) list of Enclosure objects.
Global Exporter
To set the exporter up globally, you need to declare it in the
FEED_EXPORTERS dictionary in the settings.py file:
FEED_EXPORTERS = {
'rss': 'scrapy_rss_exporter.exporters.RssItemExporter'
}
You can then use it as a FEED_FORMAT and specify the output file in the
FEED_URI:
FEED_FORMAT = 'rss'
FEED_URI = 's3://my-feeds/my-feed.rss'
Note: Bear in mind that, if you use a local file as output, scrapy
will append to an existing file resulting with an invalid RSS code. You should,
therefore, make sure to delete any existing output file before running the
spider. The s3 storage does not have this problem because
scrapy uploads are using the S3 PutObject method.
scrapy does not seem to allow to push any configuration option to an
exporter. Therefore, if you want to customize the feed title and other metadata,
you need to create a subclass and update the FEED_EXPORTERS dictionary
with the new class name:
class MyRssExporter(RssItemExporter):
def __init__(self, *args, **kwargs):
kwargs['title'] = 'My RSS'
kwargs['link'] = 'https://www.mywebsite.com'
kwargs['description'] = 'My RSS Items'
super(MyRssExporter, self).__init__(*args, **kwargs)
Per Spider Exporter
You can, of course, specify a different exporter with different settings for
each spider. Just use the custom_settings field to override the global
configuration fields:
class MySpider(scrapy.Spider):
name = "my"
start_urls = ['https://www.mywebsite.com']
custom_settings = {
'FEED_EXPORTERS': {'rss': 'project.spiders.my_spider.MyExporter'},
'FEED_FORMAT': 'rss',
'FEED_URI': 's3://my-feeds/my-feed.rss',
}
def parse(self, response):
pass
Metadata
Release files for scrapy-rss-exporter 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scrapy_rss_exporter-0.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / scrapy_rss_exporter-0.2-py2.py3-none-any.whl
| Download URL | scrapy_rss_exporter-0.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
74e73f7155b2e01ca6d51b3391f2f96c7f81dc48f61aed06547b37a1f60540e5
|
|
BLAKE2b-256 checksum How to use checksums |
05a621eefdd3c3f4ecb32e319f6646276e679b154518c3bb3a8d4063c1b0f116
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5
|
Security for scrapy-rss-exporter 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.