Older Scrapy 2.x release notes
Scrapy 2.13.4 (2025-11-17)
Security bug fixes
Improved protection against decompression bombs in
HttpCompressionMiddlewarefor responses compressed using thebranddeflatemethods: if a single compressed chunk would be larger than the response size limit (seeDOWNLOAD_MAXSIZE) when decompressed, decompression is no longer carried out. This is especially important for thebr(Brotli) method that can provide a very high compression ratio. Please, see the CVE-2025-6176 and GHSA-2qfp-q593-8484 security advisories for more information. (#7134)
Modified requirements
Other changes
Restricted the maximum supported Twisted version to
25.5.0, as Scrapy currently uses some private APIs changed in later Twisted versions. (#7142)Stopped setting the
COVERAGE_COREenvironment variable in tests, it didn’t have an effect but caused thecoveragemodule to produce a warning or an error. (#7137)Removed the documentation build dependency on the deprecated
sphinx-hoverxrefmodule. (#6786, #6922)
Scrapy 2.13.3 (2025-07-02)
Changed the values for
DOWNLOAD_DELAY(from0to1) andCONCURRENT_REQUESTS_PER_DOMAIN(from8to1) in the default project template. (#6597, #6918, #6923)Improved
scrapy.core.engine.ExecutionEnginelogic related to initialization and exception handling, fixing several cases where the spider would crash, hang or log an unhandled exception. (#6783, #6784, #6900, #6908, #6910, #6911)Fixed a Windows issue with feed exports using
scrapy.extensions.feedexport.FileFeedStoragethat caused the file to be created on the wrong drive. (#6894, #6897)Allowed running tests with Twisted 25.5.0+ again. Pytest 8.4.1+ is now required for running tests in non-pinned envs as support for the new Twisted version was added in that version. (#6893)
Fixed running tests with lxml 6.0.0+. (#6919)
Added a deprecation notice for
scrapy.spidermiddlewares.offsite.OffsiteMiddlewareto the Scrapy 2.11.2 release notes. (#6926)Updated contribution docs to refer to ruff instead of black. (#6903)
Scrapy 2.13.2 (2025-06-09)
Fixed a bug introduced in Scrapy 2.13.0 that caused results of request errbacks to be ignored when the errback was called because of a downloader error. (#6861, #6863)
Added a note about the behavior change of
scrapy.utils.reactor.is_asyncio_reactor_installedto its docs and to the “Backward-incompatible changes” section of the Scrapy 2.13.0 release notes. (#6866)Improved the message in the exception raised by
scrapy.utils.test.get_reactor_settings()when there is no reactor installed. (#6866)Updated the
scrapy.crawler.CrawlerRunnerexamples in Common Practices to install the reactor explicitly, to fix reactor-related errors with Scrapy 2.13.0 and later. (#6865)Fixed
scrapy fetchnot working with scrapy-poet. (#6872)Fixed an exception produced by
scrapy.core.engine.ExecutionEnginewhen it’s closed before being fully initialized. (#6857, #6867)Improved the README and updated the Scrapy logo in it. (#6831, #6833, #6839)
Restricted the Twisted version used in tests to below 25.5.0, as some tests fail with 25.5.0. (#6878, #6882)
Updated type hints for Twisted 25.5.0 changes. (#6882)
Removed the old artwork. (#6874)
Scrapy 2.13.1 (2025-05-28)
Gave callback requests precedence over start requests when priority values are the same.
This makes the changes from 2.13.0 to start request handling more intuitive and backward compatible. For scenarios where all requests have the same priorities, in 2.13.0 all start requests were sent before the first callback request. In 2.13.1, the same as in 2.12 and lower, start requests are only sent when there are not enough pending callback requests to reach concurrency limits.
(#6828)
Fixed a typo in the code example of Delaying start request iteration. (#6812, #6815)
Fixed a typo in the Supported callables section of the documentation. (#6822)
Made this page more prominently listed in PyPI project links. (#6826)
Scrapy 2.13.0 (2025-05-08)
Highlights:
The asyncio reactor is now enabled by default
Replaced
start_requests()(sync) withstart()(async) and changed how it is iteratedAdded the
allow_offsiterequest meta keySpider middlewares that don’t support asynchronous spider output are deprecated
Added a base class for universal spider middlewares
Modified requirements
Backward-incompatible changes
The default value of the
TWISTED_REACTORsetting was changed fromNoneto"twisted.internet.asyncioreactor.AsyncioSelectorReactor". This value was used in newly generated projects since Scrapy 2.7.0 but now existing projects that don’t explicitly set this setting will also use the asyncio reactor. You can change this setting in your project to use a different reactor. (#6659, #6713)The iteration of start requests and items no longer stops once there are requests in the scheduler, and instead runs continuously until all start requests have been scheduled.
To reproduce the previous behavior, see Delaying start request iteration. (#6729)
An unhandled exception from the
open_spider()method of a spider middleware no longer stops the crawl. (#6729)In
scrapy.core.engine.ExecutionEngine:The second parameter of
open_spider(),start_requests, has been removed. The start requests are determined by thespiderparameter instead (seestart()).The
slotattribute has been renamed to_slotand should not be used.
(#6729)
In
scrapy.core.engine, theSlotclass has been renamed to_Slotand should not be used. (#6729)The
slottelnet variable has been removed. (#6729)In
scrapy.core.spidermw.SpiderMiddlewareManager,process_start_requests()has been replaced byprocess_start(). (#6729)The
scrape_funccallable passed toscrapy.core.spidermw.SpiderMiddlewareManager.scrape_response()is now called with 2 parameters,responseandrequest, instead of 3, and must return aDeferredinstead of an iterable. (#6787)The now-deprecated
start_requests()method, when it returns an iterable instead of being defined as a generator, is now executed after the scheduler instance has been created. (#6729)When using
JOBDIR, start requests are now serialized into their own,s-suffixed priority folders. You can setSCHEDULER_START_DISK_QUEUEtoNoneor""to change that, but the side effects may be undesirable. SeeSCHEDULER_START_DISK_QUEUEfor details. (#6729)The URL length limit, set by the
URLLENGTH_LIMITsetting, is now also enforced for start requests. (#6777)Calling
scrapy.utils.reactor.is_asyncio_reactor_installedwithout an installed reactor now raises an exception instead of installing a reactor. This shouldn’t affect normal Scrapy use cases, but it may affect 3rd-party test suites that use Scrapy internals such asCrawlerand don’t install a reactor explicitly. If you are affected by this change, you most likely need to install the reactor before running Scrapy code that expects it to be installed. (#6732, #6735)The
from_settings()method ofUrlLengthMiddleware, deprecated in Scrapy 2.12.0, is removed earlier than the usual deprecation period (this was needed because after the introduction of theBaseSpiderMiddlewarebase class and switching built-in spider middlewares to it those middlewares need theCrawlerinstance at run time). Please usefrom_crawler()instead. (#6693)scrapy.utils.url.escape_ajax()is no longer called when aRequestinstance is created. It was only useful for websites supporting the_escaped_fragment_feature which most modern websites don’t support. If you still need this you can modify the URLs before passing them toRequest. (#6523, #6651)
Deprecation removals
Deprecations
The
start_requests()method ofSpideris deprecated, usestart()instead, or both to maintain support for lower Scrapy versions. (#456, #3477, #4467, #5627, #6729)The
process_start_requests()method of spider middlewares is deprecated, useprocess_start()instead, or both to maintain support for lower Scrapy versions. (#456, #3477, #4467, #5627, #6729)The
__init__method of priority queue classes (seeSCHEDULER_PRIORITY_QUEUE) should now support a keyword-onlystart_queue_clsparameter. (#6752)Spider middlewares that don’t support asynchronous spider output are deprecated. The async iterable downgrading feature, needed for using such middlewares with asynchronous callbacks and with other spider middlewares that produce asynchronous iterables, is also deprecated. Please update all such middlewares to support asynchronous spider output. (#6664)
Functions that were imported from
w3lib.urland re-exported inscrapy.utils.urlare now deprecated, you should import them fromw3lib.urldirectly. They are:scrapy.utils.url.add_or_replace_parameter()scrapy.utils.url.add_or_replace_parameters()scrapy.utils.url.any_to_uri()scrapy.utils.url.canonicalize_url()scrapy.utils.url.file_uri_to_path()scrapy.utils.url.is_url()scrapy.utils.url.parse_data_uri()scrapy.utils.url.parse_url()scrapy.utils.url.path_to_file_uri()scrapy.utils.url.safe_download_url()scrapy.utils.url.safe_url_string()scrapy.utils.url.url_query_cleaner()scrapy.utils.url.url_query_parameter()
HTTP/1.0 support code is deprecated. It was disabled by default and couldn’t be used together with HTTP/1.1. If you still need it, you should write your own download handler or copy the code from Scrapy. The deprecations include:
scrapy.core.downloader.handlers.http10.HTTP10DownloadHandlerscrapy.core.downloader.webclient.ScrapyHTTPClientFactoryscrapy.core.downloader.webclient.ScrapyHTTPPageGetterOverriding
scrapy.core.downloader.contextfactory.ScrapyClientContextFactory.getContext()
(#6634)
The following modules and functions used only in tests are deprecated:
the
scrapy.utils.testprocmodulethe
scrapy.utils.testsitemodulescrapy.utils.test.assert_gcs_environ()scrapy.utils.test.get_ftp_content_and_delete()scrapy.utils.test.get_gcs_content_and_delete()scrapy.utils.test.mock_google_cloud_storage()scrapy.utils.test.skip_if_no_boto()
If you need to use them in your tests or code, you can copy the code from Scrapy. (#6696)
scrapy.utils.test.TestSpideris deprecated. If you need an empty spider class you can usescrapy.utils.spider.DefaultSpideror create your own subclass ofscrapy.Spider. (#6678)scrapy.downloadermiddlewares.ajaxcrawl.AjaxCrawlMiddlewareis deprecated. It was disabled by default and isn’t useful for most of the existing websites. (#6523, #6651, #6656)scrapy.utils.url.escape_ajax()is deprecated. (#6523, #6651)scrapy.spiders.init.InitSpideris deprecated. If you find it useful, you can copy its code from Scrapy. (#6708, #6714)scrapy.utils.versions.scrapy_components_versions()is deprecated, usescrapy.utils.versions.get_versions()instead. (#6582)BaseDupeFilter.log()is deprecated. It does nothing and shouldn’t be called. (#4151)Passing the
spiderargument to the following methods ofScraperis deprecated:close_spider()enqueue_scrape()handle_spider_error()handle_spider_output()
(#6764)
New features
You can now yield the start requests and items of a spider from the
start()spider method and from theprocess_start()spider middleware method, both asynchronous generators.This makes it possible to use asynchronous code to generate those start requests and items, e.g. reading them from a queue service or database using an asynchronous client, without workarounds. (#456, #3477, #4467, #5627, #6729)
Start requests are now scheduled as soon as possible.
As a result, their
priorityis now taken into account as soon asCONCURRENT_REQUESTSis reached. (#456, #3477, #4467, #5627, #6729)Crawler.signalshas a newwait_for()method. (#6729)Added a new
scheduler_emptysignal. (#6729)Added new settings:
SCHEDULER_START_DISK_QUEUEandSCHEDULER_START_MEMORY_QUEUE. (#6729)Added
StartSpiderMiddleware, which setsis_start_requesttoTrueon start requests. (#6729)Exposed a new method of
Crawler.engine:needs_backout(). (#6729)Added the
allow_offsiterequest meta key that can be used instead of the more generaldont_filterrequest attribute to skip processing of the request byOffsiteMiddleware(but not by other code that checksdont_filter). (#3690, #6151, #6366)Added an optional base class for spider middlewares,
BaseSpiderMiddleware, which can be helpful for writing universal spider middlewares without boilerplate and code duplication. The built-in spider middlewares now inherit from this class. (#6693, #6777)Scrapy add-ons can now define a class method called
update_pre_crawler_settings()to update pre-crawler settings. (#6544, #6568)Added helpers for modifying component priority dictionary settings. (#6614)
Responses that use an unknown/unsupported encoding now produce a warning. If Scrapy knows that installing an additional package (such as brotli) will allow decoding the response, that will be mentioned in the warning. (#4697, #6618)
Added the
spider_exceptions/countstat which tracks the total count of exceptions (tracked also by per-typespider_exceptions/*stats). (#6739, #6740)Added the
DEFAULT_DROPITEM_LOG_LEVELsetting and thescrapy.exceptions.DropItem.log_levelattribute that allow customizing the log level of the message that is logged when an item is dropped. (#6603, #6608)Added support for the
-b, --cookiecurl argument toscrapy.Request.from_curl(). (#6684)Added the
LOG_VERSIONSsetting that allows customizing the list of software whose versions are logged when the spider starts. (#6582)Added the
WARN_ON_GENERATOR_RETURN_VALUEsetting that allows disabling run time analysis of callback code used to warn about incorrectreturnstatements in generator-based callbacks. You may need to disable this setting if this analysis breaks on your callback code. (#6731, #6738)
Improvements
Removed or postponed some calls of
itemadapter.is_item()to increase performance. (#6719)Improved the error message when running a
scrapycommand that requires a project (such asscrapy crawl) outside of a project directory. (#2349, #3426)Added an empty
ADDONSsetting to thesettings.pytemplate for new projects. (#6587)
Bug fixes
Yielding an item from
Spider.startor fromSpiderMiddleware.process_startno longer delays the next iteration of starting requests and items by up to 5 seconds. (#6729)Fixed calculation of
items_per_minuteandresponses_per_minutestats. (#6599)Fixed an error initializing
scrapy.extensions.feedexport.GCSFeedStorage. (#6617, #6628)Fixed duplicated log messages about the reactor and the event loop. (#6636, #6657)
Fixed resolving type annotations of
SitemapSpider._parse_sitemap()at run time, required by tools such as scrapy-poet. (#6665, #6671)Calling
scrapy.utils.reactor.is_asyncio_reactor_installedwithout an installed reactor now raises an exception instead of installing a reactor. (#6732, #6735)Restored support for the
x-gzipcontent encoding. (#6618)
Documentation
Documented the setting values set in the default project template. (#6762, #6775)
Improved the docs about asynchronous iterable support in spider middlewares. (#6688)
Improved the docs about using
Deferred-based APIs in coroutine-based code and included a list of such APIs. (#6677, #6734, #6776)Improved the contribution docs. (#6561, #6575)
Removed the
Splashrecommendation from the headless browser suggestion. We no longer recommend usingSplashand recommend using other headless browser solutions instead. (#6642, #6701)Added the dark mode to the HTML documentation. (#6653)
Other documentation improvements and fixes. (#4151, #6526, #6620, #6621, #6622, #6623, #6624, #6721, #6723, #6780)
Packaging
Switched the build backend from setuptools to hatchling. (#6771)
Quality assurance
Replaced most linters with ruff. (#6565, #6576, #6577, #6581, #6584, #6595, #6601, #6631)
Improved accuracy and performance of collecting test coverage. (#6255, #6610)
Fixed an error that prevented running tests from directories other than the top level source directory. (#6567)
Reduced the amount of
mockservercalls in tests to improve the overall test run time. (#6637, #6648)Fixed tests that were running the same test code more than once. (#6646, #6647, #6650)
Refactored tests to use more
pytestfeatures instead ofunittestones where possible. (#6678, #6680, #6695, #6699, #6700, #6702, #6709, #6710, #6711, #6712, #6725)Type hints improvements and fixes. (#6578, #6579, #6593, #6605, #6694)
CI and test improvements and fixes. (#5360, #6271, #6547, #6560, #6602, #6607, #6609, #6613, #6619, #6626, #6679, #6703, #6704, #6716, #6720, #6722, #6724, #6741, #6743, #6766, #6770, #6772, #6773)
Scrapy 2.12.0 (2024-11-18)
Highlights:
Dropped support for Python 3.8, added support for Python 3.13
scrapy.Spider.start_requests()can now yield itemsAdded
JsonResponse
Modified requirements
Backward-incompatible changes
User-defined cookies for HTTPS requests will have the
secureflag set toTrueunless it’s set toFalseexplicitly. This is important when these cookies are reused in HTTP requests, e.g. after a redirect to an HTTP URL. (#6357)The Reppy-based
robots.txtparser,scrapy.robotstxt.ReppyRobotParser, was removed, as it doesn’t support Python 3.9+. (#5230, #6099, #6499)The initialization API of
scrapy.pipelines.media.MediaPipelineand its subclasses was improved and it’s possible that some previously working usage scenarios will no longer work. It can only affect you if you define custom subclasses ofMediaPipelineor create instances of these pipelines viafrom_settings()or__init__()calls instead offrom_crawler()calls.Previously,
MediaPipeline.from_crawler()called thefrom_settings()method if it existed or the__init__()method otherwise, and then did some additional initialization using thecrawlerinstance. If thefrom_settings()method existed (like inFilesPipeline) it called__init__()to create the instance. It wasn’t possible to overridefrom_crawler()without callingMediaPipeline.from_crawler()from it which, in turn, couldn’t be called in some cases (including subclasses ofFilesPipeline).Now, in line with the general usage of
from_crawler()andfrom_settings()and the deprecation of the latter the recommended initialization order is the following one:All
__init__()methods should take acrawlerargument. If they also take asettingsargument they should ignore it, usingcrawler.settingsinstead. When they call__init__()of the base class they should pass thecrawlerargument to it too.A
from_settings()method shouldn’t be defined. Class-specific initialization code should go into either an overriddenfrom_crawler()method or into__init__().It’s now possible to override
from_crawler()and it’s not necessary to callMediaPipeline.from_crawler()in it if other recommendations were followed.If pipeline instances were created with
from_settings()or__init__()calls (which wasn’t supported even before, as it missed important initialization code), they should now be created withfrom_crawler()calls.
(#6540)
The
response_bodyargument ofImagesPipeline.convert_imageis now positional-only, as it was changed from optional to required. (#6500)The
convertargument ofscrapy.utils.conf.build_component_list()is now positional-only, as the preceding argument (custom) was removed. (#6500)The
overwrite_outputargument ofscrapy.utils.conf.feed_process_params_from_cli()is now positional-only, as the preceding argument (output_format) was removed. (#6500)
Deprecation removals
Removed the
scrapy.utils.request.request_fingerprint()function, deprecated in Scrapy 2.7.0. (#6212, #6213)Removed support for value
"2.6"of settingREQUEST_FINGERPRINTER_IMPLEMENTATION, deprecated in Scrapy 2.7.0. (#6212, #6213)RFPDupeFiltersubclasses now require supporting thefingerprinterparameter in their__init__method, introduced in Scrapy 2.7.0. (#6102, #6113)Removed the
scrapy.downloadermiddlewares.decompressionmodule, deprecated in Scrapy 2.7.0. (#6100, #6113)Removed the
scrapy.utils.response.response_httprepr()function, deprecated in Scrapy 2.6.0. (#6111, #6116)Spiders with spider-level HTTP authentication, i.e. with the
http_userorhttp_passattributes, must now definehttp_auth_domainas well, which was introduced in Scrapy 2.5.1. (#6103, #6113)Media pipelines methods
file_path(),file_downloaded(),get_images(),image_downloaded(),media_downloaded(),media_to_download(), andthumb_path()must now support anitemparameter, added in Scrapy 2.4.0. (#6107, #6113)The
__init__()andfrom_crawler()methods of feed storage backend classes must now support the keyword-onlyfeed_optionsparameter, introduced in Scrapy 2.4.0. (#6105, #6113)Removed the
scrapy.loader.commonandscrapy.loader.processorsmodules, deprecated in Scrapy 2.3.0. (#6106, #6113)Removed the
scrapy.utils.misc.extract_regex()function, deprecated in Scrapy 2.3.0. (#6106, #6113)Removed the
scrapy.http.JSONRequestclass, replaced withJsonRequestin Scrapy 1.8.0. (#6110, #6113)scrapy.utils.log.logformatter_adapterno longer supports missingargs,level, ormsgparameters, and no longer supports aformatparameter, all scenarios that were deprecated in Scrapy 1.0.0. (#6109, #6116)A custom class assigned to the
SPIDER_LOADER_CLASSsetting that does not implement theISpiderLoaderinterface will now raise azope.interface.verify.DoesNotImplementexception at run time. Non-compliant classes have been triggering a deprecation warning since Scrapy 1.0.0. (#6101, #6113)Removed the
--output-format/-tcommand line option, deprecated in Scrapy 2.1.0.-O <URI>:<FORMAT>should be used instead. (#6500)Running
crawl()more than once on the sameCrawlerinstance, deprecated in Scrapy 2.11.0, now raises an exception. (#6500)Subclassing
HttpCompressionMiddlewarewithout support for thecrawlerargument in__init__()and without a customfrom_crawler()method, deprecated in Scrapy 2.5.0, is no longer allowed. (#6500)Removed the
EXCEPTIONS_TO_RETRYattribute ofRetryMiddleware, deprecated in Scrapy 2.10.0. (#6500)Removed support for S3 feed exports without the boto3 package installed, deprecated in Scrapy 2.10.0. (#6500)
Removed the
scrapy.extensions.feedexport._FeedSlotclass, deprecated in Scrapy 2.10.0. (#6500)Removed the
scrapy.pipelines.images.NoimagesDropexception, deprecated in Scrapy 2.8.0. (#6500)The
response_bodyargument ofImagesPipeline.convert_imageis now required, not passing it was deprecated in Scrapy 2.8.0. (#6500)Removed the
customargument ofscrapy.utils.conf.build_component_list(), deprecated in Scrapy 2.10.0. (#6500)Removed the
scrapy.utils.reactor.get_asyncio_event_loop_policy()function, deprecated in Scrapy 2.9.0. Useasyncio.get_event_loop()and related standard library functions instead. (#6500)
Deprecations
The
from_settings()methods of the Scrapy components that have them are now deprecated.from_crawler()should now be used instead. Affected components:scrapy.mail.MailSenderscrapy.middleware.MiddlewareManagerscrapy.core.downloader.contextfactory.ScrapyClientContextFactory
(#6540)
It’s now deprecated to have a
from_settings()method but nofrom_crawler()method in 3rd-party Scrapy components. You can define a simplefrom_crawler()method that callscls.from_settings(crawler.settings)to fix this if you don’t want to refactor the code. Note that if you have afrom_crawler()method Scrapy will not call thefrom_settings()method so the latter can be removed. (#6540)The initialization API of
scrapy.pipelines.media.MediaPipelineand its subclasses was improved and some old usage scenarios are now deprecated (see also the “Backward-incompatible changes” section). Specifically:It’s deprecated to define an
__init__()method that doesn’t take acrawlerargument.It’s deprecated to call an
__init__()method without passing acrawlerargument. If it’s passed, it’s also deprecated to pass asettingsargument, which will be ignored anyway.Calling
from_settings()is deprecated, usefrom_crawler()instead.Overriding
from_settings()is deprecated, overridefrom_crawler()instead.
(#6540)
The
REQUEST_FINGERPRINTER_IMPLEMENTATIONsetting is now deprecated. (#6212, #6213)The
scrapy.utils.misc.create_instance()function is now deprecated, usescrapy.utils.misc.build_from_crawler()instead. (#5523, #5884, #6162, #6169, #6540)scrapy.core.downloader.Downloader._get_slot_key()is deprecated, usescrapy.core.downloader.Downloader.get_slot_key()instead. (#6340, #6352)scrapy.utils.defer.process_chain_both()is now deprecated. (#6397)scrapy.twisted_versionis now deprecated, you should instead usetwisted.versiondirectly (but note that it’s anincremental.Versionobject, not a tuple). (#6509, #6512)scrapy.utils.python.flatten()andscrapy.utils.python.iflatten()are now deprecated. (#6517, #6519)scrapy.utils.python.equal_attributes()is now deprecated. (#6517, #6519)scrapy.utils.request.request_authenticate()is now deprecated, you should instead just set theAuthorizationheader directly. (#6517, #6519)scrapy.utils.serialize.ScrapyJSONDecoderis now deprecated, it didn’t contain any code since Scrapy 1.0.0. (#6517, #6519)scrapy.utils.test.assert_samelines()is now deprecated. (#6517, #6519)scrapy.extensions.feedexport.build_storage()is now deprecated. You can instead call the builder callable directly. (#6540)scrapy.utils.misc.md5sum()is now deprecated. (#6264)
New features
scrapy.Spider.start_requests()can now yield items. (#5289, #6417)Note
Some spider middlewares may need to be updated for Scrapy 2.12 support before you can use them in combination with the ability to yield items from
start_requests().Added a new
Responsesubclass,JsonResponse, for responses with a JSON MIME type. (#6069, #6171, #6174)The
LogStatsextension now addsitems_per_minuteandresponses_per_minuteto the stats when the spider closes. (#4110, #4111)Added
CLOSESPIDER_PAGECOUNT_NO_ITEMwhich allows closing the spider if no items were scraped in a set amount of time. (#6434)User-defined cookies can now include the
securefield. (#6357)Added component getters to
Crawler:get_addon(),get_downloader_middleware(),get_extension(),get_item_pipeline(),get_spider_middleware(). (#6181)Slot delay updates by the AutoThrottle extension based on response latencies can now be disabled for specific requests via the
autothrottle_dont_adjust_delaymeta key. (#6246, #6527)If
SPIDER_LOADER_WARN_ONLYis set toTrue,SpiderLoaderdoes not raiseSyntaxErrorbut emits a warning instead. (#6483, #6484)Added support for multiple-compressed responses (ones with several encodings in the
Content-Encodingheader). (#5143, #5964, #6063)Added support for multiple standard values in
REFERRER_POLICY. (#6381)Added support for brotlicffi (previously named brotlipy). brotli is still recommended but only brotlicffi works on PyPy. (#6263, #6269)
Added
MetadataContractthat sets the request meta. (#6468, #6469)
Improvements
Extended the list of file extensions that
LinkExtractorignores by default. (#6074, #6125)scrapy.utils.httpobj.urlparse_cached()is now used in more places instead ofurllib.parse.urlparse(). (#6228, #6229)
Bug fixes
MediaPipelineis now an abstract class and its methods that were expected to be overridden in subclasses are now abstract methods. (#6365, #6368)Fixed handling of invalid
@-prefixed lines in contract extraction. (#6383, #6388)Importing
scrapy.extensions.telnetno longer installs the default reactor. (#6432)Reduced log verbosity for dropped requests that was increased in 2.11.2. (#6433, #6475)
Documentation
Added
SECURITY.mdthat documents the security policy. (#5364, #6051)Example code for running Scrapy from a script no longer imports
twisted.internet.reactorat the top level, which caused problems with non-default reactors when this code was used unmodified. (#6361, #6374)Documented the
SpiderStateextension. (#6278, #6522)Other documentation improvements and fixes. (#5920, #6094, #6177, #6200, #6207, #6216, #6223, #6317, #6328, #6389, #6394, #6402, #6411, #6427, #6429, #6440, #6448, #6449, #6462, #6497, #6506, #6507, #6524)
Quality assurance
Fully covered the code with type hints (except for the most complicated parts, mostly related to
twisted.web.httpand other Twisted parts without type hints). (#5989, #6097, #6127, #6129, #6130, #6133, #6143, #6191, #6268, #6274, #6275, #6276, #6279, #6325, #6326, #6333, #6335, #6336, #6337, #6341, #6353, #6356, #6370, #6371, #6384, #6385, #6387, #6391, #6395, #6414, #6422, #6460, #6466, #6472, #6494, #6498, #6516)Added
flake8-bugbear,flake8-comprehensions,flake8-debugger,flake8-docstrings,flake8-string-formatandflake8-type-checkingto thepre-commitconfiguration. (#6406, #6413)CI and test improvements and fixes. (#5285, #5454, #5997, #6078, #6084, #6087, #6132, #6153, #6154, #6201, #6231, #6232, #6235, #6236, #6242, #6245, #6253, #6258, #6259, #6270, #6272, #6286, #6290, #6296 #6367, #6372, #6403, #6416, #6435, #6489, #6501, #6504, #6511, #6543, #6545)
Code cleanups. (#6196, #6197, #6198, #6199, #6254, #6257, #6285, #6305, #6343, #6349, #6386, #6415, #6463, #6470, #6499, #6505, #6510, #6531, #6542)
Other
Issue tracker improvements. (#6066)
Scrapy 2.11.2 (2024-05-14)
Security bug fixes
Redirects to non-HTTP protocols are no longer followed. Please, see the 23j4-mw76-5v7h security advisory for more information. (#457)
The
Authorizationheader is now dropped on redirects to a different scheme (http://orhttps://) or port, even if the domain is the same. Please, see the 4qqq-9vqf-3h3f security advisory for more information.When using system proxy settings that are different for
http://andhttps://, redirects to a different URL scheme will now also trigger the corresponding change in proxy settings for the redirected request. Please, see the jm3v-qxmh-hxwv security advisory for more information. (#767)Spider.allowed_domainsis now enforced for all requests, and not only requests from spider callbacks. (#1042, #2241, #6358)xmliter_lxml()no longer resolves XML entities. (#6265)defusedxml is now used to make
scrapy.http.request.rpc.XmlRpcRequestmore secure. (#6250, #6251)
Deprecations
scrapy.spidermiddlewares.offsite.OffsiteMiddleware(a spider middleware) is now deprecated and not enabled by default. The new downloader middleware with the same functionality,scrapy.downloadermiddlewares.offsite.OffsiteMiddleware, is enabled instead. (#2241, #6358)
Bug fixes
Restored support for brotlipy, which had been dropped in Scrapy 2.11.1 in favor of brotli. (#6261)
Note
brotlipy is deprecated, both in Scrapy and upstream. Use brotli instead if you can.
Make
METAREFRESH_IGNORE_TAGS["noscript"]by default. This preventsMetaRefreshMiddlewarefrom following redirects that would not be followed by web browsers with JavaScript enabled. (#6342, #6347)During feed export, do not close the underlying file from built-in post-processing plugins. (#5932, #6178, #6239)
LinkExtractornow properly applies theuniqueandcanonicalizeparameters. (#3273, #6221)Do not initialize the scheduler disk queue if
JOBDIRis an empty string. (#6121, #6124)Fix
Spider.loggernot logging custom extra information. (#6323, #6324)robots.txtfiles with a non-UTF-8 encoding no longer prevent parsing the UTF-8-compatible (e.g. ASCII) parts of the document. (#6292, #6298)scrapy.http.cookies.WrappedRequest.get_header()no longer raises an exception ifdefaultisNone. (#6308, #6310)Selectornow usesscrapy.utils.response.get_base_url()to determine the base URL of a givenResponse. (#6265)The
media_to_download()method of media pipelines now logs exceptions before stripping them. (#5067, #5068)When passing a callback to the
parsecommand, build the callback callable with the right signature. (#6182)
Documentation
Add a FAQ entry about creating blank requests. (#6203, #6208)
Document that
scrapy.Selector.typecan be"json". (#6328, #6334)
Quality assurance
Scrapy 2.11.1 (2024-02-14)
Highlights:
Security bug fixes.
Support for Twisted >= 23.8.0.
Documentation improvements.
Security bug fixes
Addressed ReDoS vulnerabilities:
scrapy.utils.iterators.xmliteris now deprecated in favor ofxmliter_lxml(), whichXMLFeedSpidernow uses.To minimize the impact of this change on existing code,
xmliter_lxml()now supports indicating the node namespace with a prefix in the node name, and big files with highly nested trees when using libxml2 2.7+.Fixed regular expressions in the implementation of the
open_in_browser()function.
Please, see the cc65-xxvf-f7r9 security advisory for more information.
DOWNLOAD_MAXSIZEandDOWNLOAD_WARNSIZEnow also apply to the decompressed response body. Please, see the 7j7m-v7m3-jqm7 security advisory for more information.Also in relation with the 7j7m-v7m3-jqm7 security advisory, the deprecated
scrapy.downloadermiddlewares.decompressionmodule has been removed.The
Authorizationheader is now dropped on redirects to a different domain. Please, see the cw9j-q3vf-hrrv security advisory for more information.
Modified requirements
Bug fixes
Documentation
Improved documentation for
Crawlerinitialization changes made in the 2.11.0 release. (#6057, #6147)Extended documentation for
Request.meta. (#5565)Fixed the
dont_merge_cookiesdocumentation. (#5936, #6077)Added a link to Zyte’s export guides to the feed exports documentation. (#6183)
Added a missing note about backward-incompatible changes in
PythonItemExporterto the 2.11.0 release notes. (#6060, #6081)Added a missing note about removing the deprecated
scrapy.utils.boto.is_botocore()function to the 2.8.0 release notes. (#6056, #6061)Other documentation improvements. (#6128, #6144, #6163, #6190, #6192)
Quality assurance
Scrapy 2.11.0 (2023-09-18)
Highlights:
Spiders can now modify settings in their
from_crawler()methods, e.g. based on spider arguments.Periodic logging of stats.
Backward-incompatible changes
Most of the initialization of
scrapy.crawler.Crawlerinstances is now done incrawl(), so the state of instances before that method is called is now different compared to older Scrapy versions. We do not recommend using theCrawlerinstances beforecrawl()is called. (#6038)scrapy.Spider.from_crawler()is now called before the initialization of various components previously initialized inscrapy.crawler.Crawler.__init__()and before the settings are finalized and frozen. This change was needed to allow changing the settings inscrapy.Spider.from_crawler(). If you want to access the final setting values and the initializedCrawlerattributes in the spider code as early as possible you can do this inscrapy.Spider.start_requests()or in a handler of theengine_startedsignal. (#6038)The
TextResponse.jsonmethod now requires the response to be in a valid JSON encoding (UTF-8, UTF-16, or UTF-32). If you need to deal with JSON documents in an invalid encoding, usejson.loads(response.text)instead. (#6016)PythonItemExporterused the binary output by default but it no longer does. (#6006, #6007)
Deprecation removals
Removed the binary export mode of
PythonItemExporter, deprecated in Scrapy 1.1.0. (#6006, #6007)Note
If you are using this Scrapy version on Scrapy Cloud with a stack that includes an older Scrapy version and get a “TypeError: Unexpected options: binary” error, you may need to add
scrapinghub-entrypoint-scrapy >= 0.14.1to your project requirements or switch to a stack that includes Scrapy 2.11.Removed the
CrawlerRunner.spidersattribute, deprecated in Scrapy 1.0.0, useCrawlerRunner.spider_loaderinstead. (#6010)The
scrapy.utils.response.response_httprepr()function, deprecated in Scrapy 2.6.0, has now been removed. (#6111)
Deprecations
Running
crawl()more than once on the samescrapy.crawler.Crawlerinstance is now deprecated. (#1587, #6040)
New features
Spiders can now modify settings in their
from_crawler()method, e.g. based on spider arguments. (#1305, #1580, #2392, #3663, #6038)Added the
PeriodicLogextension which can be enabled to log stats and/or their differences periodically. (#5926)Optimized the memory usage in
TextResponse.jsonby removing unnecessary body decoding. (#5968, #6016)Links to
.webpfiles are now ignored by link extractors. (#6021)
Bug fixes
Fixed logging enabled add-ons. (#6036)
Fixed
MailSenderproducing invalid message bodies when thecharsetargument is passed tosend(). (#5096, #5118)Fixed an exception when accessing
self.EXCEPTIONS_TO_RETRYfrom a subclass ofRetryMiddleware. (#6049, #6050)scrapy.settings.BaseSettings.getdictorlist(), used to parseFEED_EXPORT_FIELDS, now handles tuple values. (#6011, #6013)Calls to
datetime.utcnow(), no longer recommended to be used, have been replaced with calls todatetime.now()with a timezone. (#6014)
Documentation
Quality assurance
Scrapy 2.10.1 (2023-08-30)
Scrapy 2.10.0 (2023-08-04)
Highlights:
Added Python 3.12 support, dropped Python 3.7 support.
The new add-ons framework simplifies configuring 3rd-party components that support it.
Exceptions to retry can now be configured.
Many fixes and improvements for feed exports.
Modified requirements
Backward-incompatible changes
The value of the
FEED_STORE_EMPTYsetting is nowTrueinstead ofFalse. In earlier Scrapy versions empty files were created even when this setting wasFalse(which was a bug that is now fixed), so the new default should keep the old behavior. (#872, #5847)
Deprecation removals
When a function is assigned to the
FEED_URI_PARAMSsetting, returningNoneor modifying theparamsinput parameter, deprecated in Scrapy 2.6, is no longer supported. (#5994, #5996)The
scrapy.utils.reqsermodule, deprecated in Scrapy 2.6, is removed. (#5994, #5996)The
scrapy.squeuesclassesPickleFifoDiskQueueNonRequest,PickleLifoDiskQueueNonRequest,MarshalFifoDiskQueueNonRequest, andMarshalLifoDiskQueueNonRequest, deprecated in Scrapy 2.6, are removed. (#5994, #5996)The property
open_spidersand the methodshas_capacityandscheduleofscrapy.core.engine.ExecutionEngine, deprecated in Scrapy 2.6, are removed. (#5994, #5998)Passing a
spiderargument to thespider_is_idle(),crawl()anddownload()methods ofscrapy.core.engine.ExecutionEngine, deprecated in Scrapy 2.6, is no longer supported. (#5994, #5998)
Deprecations
scrapy.utils.datatypes.CaselessDictis deprecated, usescrapy.utils.datatypes.CaseInsensitiveDictinstead. (#5146)Passing the
customargument toscrapy.utils.conf.build_component_list()is deprecated, it was used in the past to mergeFOOandFOO_BASEsetting values but now Scrapy usesscrapy.settings.BaseSettings.getwithbase()to do the same. Code that uses this argument and cannot be switched togetwithbase()can be switched to merging the values explicitly. (#5726, #5923)
New features
Added support for Scrapy add-ons. (#5950)
Added the
RETRY_EXCEPTIONSsetting that configures which exceptions will be retried byRetryMiddleware. (#2701, #5929)Added the possiiblity to close the spider if no items were produced in the specified time, configured by
CLOSESPIDER_TIMEOUT_NO_ITEM. (#5979)Added support for the
AWS_REGION_NAMEsetting to feed exports. (#5980)Added support for using
pathlib.Pathobjects that refer to absolute Windows paths in theFEEDSsetting. (#5939)
Bug fixes
Fixed creating empty feeds even with
FEED_STORE_EMPTY=False. (#872, #5847)Fixed using absolute Windows paths when specifying output files. (#5969, #5971)
Fixed problems with uploading large files to S3 by switching to multipart uploads (requires boto3). (#960, #5735, #5833)
Fixed the JSON exporter writing extra commas when some exceptions occur. (#3090, #5952)
Fixed the “read of closed file” error in the CSV exporter. (#5043, #5705)
Fixed an error when a component added by the class object throws
NotConfiguredwith a message. (#5950, #5992)Added the missing
scrapy.settings.BaseSettings.pop()method. (#5959, #5960, #5963)Added
CaseInsensitiveDictas a replacement forCaselessDictthat fixes some API inconsistencies. (#5146)
Documentation
Documented
scrapy.Spider.update_settings(). (#5745, #5846)Documented possible problems with early Twisted reactor installation and their solutions. (#5981, #6000)
Added examples of making additional requests in callbacks. (#5927)
Clarified the docs about request objects on redirection. (#5707, #5937)
Quality assurance
Added support for running tests against the installed Scrapy version. (#4914, #5949)
Fixed the
test_utils_asyncio.AsyncioTest.test_set_asyncio_event_looptest. (#5951)Fixed the
test_feedexport.BatchDeliveriesTest.test_batch_path_differtest on Windows. (#5847)Enabled CI runs for Python 3.11 on Windows. (#5999)
Simplified skipping tests that depend on
uvloop. (#5984)Fixed the
extra-deps-pinnedtox env. (#5948)
Scrapy 2.9.0 (2023-05-08)
Highlights:
Per-domain download settings.
Compatibility with new cryptography and new parsel.
JMESPath selectors from the new parsel.
Bug fixes.
Deprecations
scrapy.extensions.feedexport._FeedSlotis renamed toscrapy.extensions.feedexport.FeedSlotand the old name is deprecated. (#5876)
New features
Settings corresponding to
DOWNLOAD_DELAY,CONCURRENT_REQUESTS_PER_DOMAINandRANDOMIZE_DOWNLOAD_DELAYcan now be set on a per-domain basis via the newDOWNLOAD_SLOTSsetting. (#5328)Added
TextResponse.jmespath(), a shortcut for JMESPath selectors available since parsel 1.8.1. (#5894, #5915)Added
feed_slot_closedandfeed_exporter_closedsignals. (#5876)Added
scrapy.utils.request.request_to_curl(), a function to produce a curl command from aRequestobject. (#5892)Values of
FILES_STOREandIMAGES_STOREcan now bepathlib.Pathinstances. (#5801)
Bug fixes
Fixed an error when using feed postprocessing with S3 storage. (#5500, #5581)
Added the missing
scrapy.settings.BaseSettings.setdefault()method. (#5811, #5821)Fixed an error when using cryptography 40.0.0+ and
DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGINGis enabled. (#5857, #5858)The checksums returned by
FilesPipelinefor files on Google Cloud Storage are no longer Base64-encoded. (#5874, #5891)scrapy.utils.request.request_from_curl()now supports $-prefixed string values for the curl--data-rawargument, which are produced by browsers for data that includes certain symbols. (#5899, #5901)The
parsecommand now also works with async generator callbacks. (#5819, #5824)The
genspidercommand now properly works with HTTPS URLs. (#3553, #5808)LinkExtractornow skips certain malformed URLs instead of raising an exception. (#5881)scrapy.utils.python.get_func_args()now supports more types of callables. (#5872, #5885)Fixed an error when processing non-UTF8 values of
Content-Typeheaders. (#5914, #5917)Fixed an error breaking user handling of send failures in
scrapy.mail.MailSender.send(). (#1611, #5880)
Documentation
Quality assurance
Tests for most of the examples in the docs are now run as a part of CI, found problems were fixed. (#5816, #5826, #5919)
Removed usage of deprecated Python classes. (#5849)
Silenced
include-ignoredwarnings from coverage. (#5820)Fixed a random failure of the
test_feedexport.test_batch_path_differtest. (#5855, #5898)Updated docstrings to match output produced by parsel 1.8.1 so that they don’t cause test failures. (#5902, #5919)
Scrapy 2.8.0 (2023-02-02)
This is a maintenance release, with minor features, bug fixes, and cleanups.
Deprecation removals
The
scrapy.utils.gz.read1function, deprecated in Scrapy 2.0, has now been removed. Use theread1()method ofGzipFileinstead. (#5719)The
scrapy.utils.python.to_native_strfunction, deprecated in Scrapy 2.0, has now been removed. Usescrapy.utils.python.to_unicode()instead. (#5719)The
scrapy.utils.python.MutableChain.nextmethod, deprecated in Scrapy 2.0, has now been removed. Use__next__()instead. (#5719)The
scrapy.linkextractors.FilteringLinkExtractorclass, deprecated in Scrapy 2.0, has now been removed. UseLinkExtractorinstead. (#5720)Support for using environment variables prefixed with
SCRAPY_to override settings, deprecated in Scrapy 2.0, has now been removed. (#5724)Support for the
noconnectquery string argument in proxy URLs, deprecated in Scrapy 2.0, has now been removed. We expect proxies that used to need it to work fine without it. (#5731)The
scrapy.utils.python.retry_on_eintrfunction, deprecated in Scrapy 2.3, has now been removed. (#5719)The
scrapy.utils.python.WeakKeyCacheclass, deprecated in Scrapy 2.4, has now been removed. (#5719)The
scrapy.utils.boto.is_botocore()function, deprecated in Scrapy 2.4, has now been removed. (#5719)
Deprecations
New features
Applied black coding style to files generated with the
genspiderandstartprojectcommands. (#5809, #5814)FEED_EXPORT_ENCODINGis now set to"utf-8"in thesettings.pyfile that thestartprojectcommand generates. With this value, JSON exports won’t force the use of escape sequences for non-ASCII characters. (#5797, #5800)The
MemoryUsageextension now logs the peak memory usage during checks, and the binary unit MiB is now used to avoid confusion. (#5717, #5722, #5727)The
callbackparameter ofRequestcan now be set toscrapy.http.request.NO_CALLBACK(), to distinguish it fromNone, as the latter indicates that the default spider callback (parse()) is to be used. (#5798)
Bug fixes
Enabled unsafe legacy SSL renegotiation to fix access to some outdated websites. (#5491, #5790)
Fixed STARTTLS-based email delivery not working with Twisted 21.2.0 and better. (#5386, #5406)
Fixed the
finish_exporting()method of item exporters not being called for empty files. (#5537, #5758)Fixed HTTP/2 responses getting only the last value for a header when multiple headers with the same name are received. (#5777)
Fixed an exception raised by the
shellcommand on some cases when using asyncio. (#5740, #5742, #5748, #5759, #5760, #5771)When using
CrawlSpider, callback keyword arguments (cb_kwargs) added to a request in theprocess_requestcallback of aRulewill no longer be ignored. (#5699)The images pipeline no longer re-encodes JPEG files. (#3055, #3689, #4753)
Fixed the handling of transparent WebP images by the images pipeline. (#3072, #5766, #5767)
scrapy.shell.inspect_response()no longer inhibitsSIGINT(Ctrl+C). (#2918)LinkExtractorwithunique=Falseno longer filters out links that have identical URL and text. (#3798, #3799, #4695, #5458)RobotsTxtMiddlewarenow ignores URL protocols that do not supportrobots.txt(data://,file://). (#5807)Silenced the
filelockdebug log messages introduced in Scrapy 2.6. (#5753, #5754)Fixed the output of
scrapy -hshowing an unintended**commands**line. (#5709, #5711, #5712)Made the active project indication in the output of commands more clear. (#5715)
Documentation
Documented how to debug spiders from Visual Studio Code. (#5721)
Documented how
DOWNLOAD_DELAYaffects per-domain concurrency. (#5083, #5540)Improved consistency. (#5761)
Quality assurance
Applied black coding style, sorted import statements, and introduced pre-commit. (#4654, #4658, #5734, #5737, #5806, #5810)
Addressed many issues reported by Pylint. (#5677)
Improved code readability. (#5736)
Improved package metadata. (#5768)
Removed unnecessary
OrderedDictusages. (#5795)Removed unnecessary
__str__definitions. (#5150)Removed obsolete code and comments. (#5725, #5729, #5730, #5732)
Fixed test and CI issues. (#5749, #5750, #5756, #5762, #5765, #5780, #5781, #5782, #5783, #5785, #5786)
Scrapy 2.7.1 (2022-11-02)
New features
Relaxed the restriction introduced in 2.6.2 so that the
Proxy-Authorizationheader can again be set explicitly, as long as the proxy URL in theproxymetadata has no other credentials, and for as long as that proxy URL remains the same; this restores compatibility with scrapy-zyte-smartproxy 2.1.0 and older (#5626).
Bug fixes
Using
-O/--overwrite-outputand-t/--output-formatoptions together now produces an error instead of ignoring the former option (#5516, #5605).Replaced deprecated
asyncioAPIs that implicitly use the current event loop with code that explicitly requests a loop from the event loop policy (#5685, #5689).Fixed uses of deprecated Scrapy APIs in Scrapy itself (#5588, #5589).
Improved code that checks if generators return values, so that it no longer fails on decorated methods and partial methods (#5323, #5592, #5599, #5691).
Documentation
Quality assurance
Scrapy 2.7.0 (2022-10-17)
Highlights:
Added Python 3.11 support, dropped Python 3.6 support
Improved support for asynchronous callbacks
Asyncio support is enabled by default on new projects
Output names of item fields can now be arbitrary strings
Centralized request fingerprinting configuration is now possible
Modified requirements
Python 3.7 or greater is now required; support for Python 3.6 has been dropped. Support for the upcoming Python 3.11 has been added.
The minimum required version of some dependencies has changed as well:
lxml: 3.5.0 → 4.3.0
Pillow (images pipeline): 4.0.0 → 7.1.0
zope.interface: 5.0.0 → 5.1.0
Deprecations
ImagesPipeline.thumb_pathmust now accept anitemparameter (#5504, #5508).The
scrapy.downloadermiddlewares.decompressionmodule is now deprecated (#5546, #5547).
New features
The
process_spider_output()method of spider middlewares can now be defined as an asynchronous generator (#4978).The output of
Requestcallbacks defined as coroutines is now processed asynchronously (#4978).CrawlSpidernow supports asynchronous callbacks (#5657).New projects created with the
startprojectcommand have asyncio support enabled by default (#5590, #5679).The
FEED_EXPORT_FIELDSsetting can now be defined as a dictionary to customize the output name of item fields, lifting the restriction that required output names to be valid Python identifiers, e.g. preventing them to have whitespace (#1008, #3266, #3696).You can now customize request fingerprinting through the new
REQUEST_FINGERPRINTER_CLASSsetting, instead of having to change it on every Scrapy component that relies on request fingerprinting (#900, #3420, #4113, #4762, #4524).jsonlis now supported and encouraged as a file extension for JSON Lines files (#4848).ImagesPipeline.thumb_pathnow receives the source item (#5504, #5508).
Bug fixes
When using Google Cloud Storage with a media pipeline,
FILES_EXPIRESnow also works whenFILES_STOREdoes not point at the root of your Google Cloud Storage bucket (#5317, #5318).The
parsecommand now supports asynchronous callbacks (#5424, #5577).When using the
parsecommand with a URL for which there is no available spider, an exception is no longer raised (#3264, #3265, #5375, #5376, #5497).TextResponsenow gives higher priority to the byte order mark when determining the text encoding of the response body, following the HTML living standard (#5601, #5611).MIME sniffing takes the response body into account in FTP and HTTP/1.0 requests, as well as in cached requests (#4873).
MIME sniffing now detects valid HTML 5 documents even if the
htmltag is missing (#4873).An exception is now raised if
ASYNCIO_EVENT_LOOPhas a value that does not match the asyncio event loop actually installed (#5529).Fixed
Headers.getlist()returning only the last header (#5515, #5526).Fixed
LinkExtractornot ignoring thetar.gzfile extension by default (#1837, #2067, #4066)
Documentation
Clarified the return type of
Spider.parse(#5602, #5608).To enable
HttpCompressionMiddlewareto do brotli compression, installing brotli is now recommended instead of installing brotlipy, as the former provides a more recent version of brotli.Signal documentation now mentions coroutine support and uses it in code examples (#4852, #5358).
Avoiding getting banned now recommends Common Crawl instead of Google cache (#3582, #5432).
The new Components topic covers enforcing requirements on Scrapy components, like downloader middlewares, extensions, item pipelines, spider middlewares, and more; Enforcing asyncio as a requirement has also been added (#4978).
Settings now indicates that setting values must be picklable (#5607, #5629).
Removed outdated documentation (#5446, #5373, #5369, #5370, #5554).
Fixed typos (#5442, #5455, #5457, #5461, #5538, #5553, #5558, #5624, #5631).
Fixed other issues (#5283, #5284, #5559, #5567, #5648, #5659, #5665).
Quality assurance
Scrapy 2.6.3 (2022-09-27)
Added support for pyOpenSSL 22.1.0, removing support for SSLv3 (#5634, #5635, #5636).
Upgraded the minimum versions of the following dependencies:
cryptography: 2.0 → 3.3
pyOpenSSL: 16.2.0 → 21.0.0
service_identity: 16.0.0 → 18.1.0
Twisted: 17.9.0 → 18.9.0
zope.interface: 4.1.3 → 5.0.0
Scrapy 2.6.2 (2022-07-25)
Security bug fix:
When
HttpProxyMiddlewareprocesses a request withproxymetadata, and thatproxymetadata includes proxy credentials,HttpProxyMiddlewaresets theProxy-Authorizationheader, but only if that header is not already set.There are third-party proxy-rotation downloader middlewares that set different
proxymetadata every time they process a request.Because of request retries and redirects, the same request can be processed by downloader middlewares more than once, including both
HttpProxyMiddlewareand any third-party proxy-rotation downloader middleware.These third-party proxy-rotation downloader middlewares could change the
proxymetadata of a request to a new value, but fail to remove theProxy-Authorizationheader from the previous value of theproxymetadata, causing the credentials of one proxy to be sent to a different proxy.To prevent the unintended leaking of proxy credentials, the behavior of
HttpProxyMiddlewareis now as follows when processing a request:If the request being processed defines
proxymetadata that includes credentials, theProxy-Authorizationheader is always updated to feature those credentials.If the request being processed defines
proxymetadata without credentials, theProxy-Authorizationheader is removed unless it was originally defined for the same proxy URL.To remove proxy credentials while keeping the same proxy URL, remove the
Proxy-Authorizationheader.If the request has no
proxymetadata, or that metadata is a falsy value (e.g.None), theProxy-Authorizationheader is removed.It is no longer possible to set a proxy URL through the
proxymetadata but set the credentials through theProxy-Authorizationheader. Set proxy credentials through theproxymetadata instead.
Also fixes the following regressions introduced in 2.6.0:
CrawlerProcesssupports again crawling multiple spiders (#5435, #5436)Installing a Twisted reactor before Scrapy does (e.g. importing
twisted.internet.reactorsomewhere at the module level) no longer prevents Scrapy from starting, as long as a different reactor is not specified inTWISTED_REACTOR(#5525, #5528)Fixed an exception that was being logged after the spider finished under certain conditions (#5437, #5440)
The
--output/-ocommand-line parameter supports again a value starting with a hyphen (#5444, #5445)The
scrapy parse -hcommand no longer throws an error (#5481, #5482)
Scrapy 2.6.1 (2022-03-01)
Fixes a regression introduced in 2.6.0 that would unset the request method when following redirects.
Scrapy 2.6.0 (2022-03-01)
Highlights:
Python 3.10 support
asyncio support is no longer considered experimental, and works out-of-the-box on Windows regardless of your Python version
Feed exports now support
pathlib.Pathoutput paths and per-feed item filtering and post-processing
Security bug fixes
When a
Requestobject with cookies defined gets a redirect response causing a newRequestobject to be scheduled, the cookies defined in the originalRequestobject are no longer copied into the newRequestobject.If you manually set the
Cookieheader on aRequestobject and the domain name of the redirect URL is not an exact match for the domain of the URL of the originalRequestobject, yourCookieheader is now dropped from the newRequestobject.The old behavior could be exploited by an attacker to gain access to your cookies. Please, see the cjvr-mfj7-j4j8 security advisory for more information.
Note
It is still possible to enable the sharing of cookies between different domains with a shared domain suffix (e.g.
example.comand any subdomain) by defining the shared domain suffix (e.g.example.com) as the cookie domain when defining your cookies. See the documentation of theRequestclass for more information.When the domain of a cookie, either received in the
Set-Cookieheader of a response or defined in aRequestobject, is set to a public suffix, the cookie is now ignored unless the cookie domain is the same as the request domain.The old behavior could be exploited by an attacker to inject cookies from a controlled domain into your cookiejar that could be sent to other domains not controlled by the attacker. Please, see the mfjm-vh54-3f96 security advisory for more information.
Modified requirements
The h2 dependency is now optional, only needed to enable HTTP/2 support. (#5113)
Backward-incompatible changes
The
formdataparameter ofFormRequest, if specified for a non-POST request, now overrides the URL query string, instead of being appended to it. (#2919, #3579)When a function is assigned to the
FEED_URI_PARAMSsetting, now the return value of that function, and not theparamsinput parameter, will determine the feed URI parameters, unless that return value isNone. (#4962, #4966)In
scrapy.core.engine.ExecutionEngine, methodscrawl(),download(),schedule(), andspider_is_idle()now raiseRuntimeErrorif called beforeopen_spider(). (#5090)These methods used to assume that
ExecutionEngine.slothad been defined by a prior call toopen_spider(), so they were raisingAttributeErrorinstead.If the API of the configured scheduler does not meet expectations,
TypeErroris now raised at startup time. Before, other exceptions would be raised at run time. (#3559)The
_encodingfield of serializedRequestobjects is now namedencoding, in line with all other fields (#5130)
Deprecation removals
scrapy.http.TextResponse.body_as_unicode, deprecated in Scrapy 2.2, has now been removed. (#5393)scrapy.item.BaseItem, deprecated in Scrapy 2.2, has now been removed. (#5398)scrapy.item.DictItem, deprecated in Scrapy 1.8, has now been removed. (#5398)scrapy.Spider.make_requests_from_url, deprecated in Scrapy 1.4, has now been removed. (#4178, #4356)
Deprecations
When a function is assigned to the
FEED_URI_PARAMSsetting, returningNoneor modifying theparamsinput parameter is now deprecated. Return a new dictionary instead. (#4962, #4966)scrapy.utils.reqseris deprecated. (#5130)Instead of
request_to_dict(), use the newRequest.to_dict()method.Instead of
request_from_dict(), use the newscrapy.utils.request.request_from_dict()function.
In
scrapy.squeues, the following queue classes are deprecated:PickleFifoDiskQueueNonRequest,PickleLifoDiskQueueNonRequest,MarshalFifoDiskQueueNonRequest, andMarshalLifoDiskQueueNonRequest. You should instead use:PickleFifoDiskQueue,PickleLifoDiskQueue,MarshalFifoDiskQueue, andMarshalLifoDiskQueue. (#5117)Many aspects of
scrapy.core.engine.ExecutionEnginethat come from a time when this class could handle multipleSpiderobjects at a time have been deprecated. (#5090)The
has_capacity()method is deprecated.The
schedule()method is deprecated, usecrawl()ordownload()instead.The
open_spidersattribute is deprecated, usespiderinstead.The
spiderparameter is deprecated for the following methods:spider_is_idle()crawl()download()
Instead, call
open_spider()first to set theSpiderobject.
scrapy.utils.response.response_httprepr()is now deprecated. (#4972)
New features
You can now use item filtering to control which items are exported to each output feed. (#4575, #5178, #5161, #5203)
You can now apply post-processing to feeds, and built-in post-processing plugins are provided for output file compression. (#2174, #5168, #5190)
The
FEEDSsetting now supportspathlib.Pathobjects as keys. (#5383, #5384)Enabling asyncio while using Windows and Python 3.8 or later will automatically switch the asyncio event loop to one that allows Scrapy to work. See Windows-specific notes. (#4976, #5315)
The
genspidercommand now supports a start URL instead of a domain name. (#4439)scrapy.utils.defergained 2 new functions,deferred_to_future()andmaybe_deferred_to_future(), to help await on Deferreds when using the asyncio reactor. (#5288)Amazon S3 feed export storage gained support for temporary security credentials (
AWS_SESSION_TOKEN) and endpoint customization (AWS_ENDPOINT_URL). (#4998, #5210)New
LOG_FILE_APPENDsetting to allow truncating the log file. (#5279)Request.cookiesvalues that arebool,floatorintare cast tostr. (#5252, #5253)You may now raise
CloseSpiderfrom a handler of thespider_idlesignal to customize the reason why the spider is stopping. (#5191)When using
HttpProxyMiddleware, the proxy URL for non-HTTPS HTTP/1.1 requests no longer needs to include a URL scheme. (#4505, #4649)All built-in queues now expose a
peekmethod that returns the next queue object (likepop) but does not remove the returned object from the queue. (#5112)If the underlying queue does not support peeking (e.g. because you are not using
queuelib1.6.1 or later), thepeekmethod raisesNotImplementedError.RequestandResponsenow have anattributesattribute that makes subclassing easier. ForRequest, it also allows subclasses to work withscrapy.utils.request.request_from_dict(). (#1877, #5130, #5218)The
open()andclose()methods of the scheduler are now optional. (#3559)HTTP/1.1
TunnelErrorexceptions now only truncate response bodies longer than 1000 characters, instead of those longer than 32 characters, making it easier to debug such errors. (#4881, #5007)ItemLoadernow supports non-text responses. (#5145, #5269)
Bug fixes
The
TWISTED_REACTORandASYNCIO_EVENT_LOOPsettings are no longer ignored if defined incustom_settings. (#4485, #5352)Removed a module-level Twisted reactor import that could prevent using the asyncio reactor. (#5357)
The
startprojectcommand works with existing folders again. (#4665, #4676)The
FEED_URI_PARAMSsetting now behaves as documented. (#4962, #4966)Request.cb_kwargsonce again allows thecallbackkeyword. (#5237, #5251, #5264)Made
scrapy.utils.response.open_in_browser()support more complex HTML. (#5319, #5320)Fixed
CSVFeedSpider.quotecharbeing interpreted as the CSV file encoding. (#5391, #5394)Added missing setuptools to the list of dependencies. (#5122)
LinkExtractornow also works as expected with links that have comma-separatedrelattribute values includingnofollow. (#5225)Fixed a
TypeErrorthat could be raised during feed export parameter parsing. (#5359)
Documentation
asyncio support is no longer considered experimental. (#5332)
Included Windows-specific help for asyncio usage. (#4976, #5315)
Rewrote Using a headless browser with up-to-date best practices. (#4484, #4613)
Documented local file naming in media pipelines. (#5069, #5152)
Frequently Asked Questions now covers spider file name collision issues. (#2680, #3669)
Provided better context and instructions to disable the
URLLENGTH_LIMITsetting. (#5135, #5250)Documented that Reppy parser does not support Python 3.9+. (#5226, #5231)
Documented the scheduler component. (#3537, #3559)
Documented the method used by media pipelines to determine if a file has expired. (#5120, #5254)
Running multiple spiders in the same process now features
scrapy.utils.project.get_project_settings()usage. (#5070)Running multiple spiders in the same process now covers what happens when you define different per-spider values for some settings that cannot differ at run time. (#4485, #5352)
Extended the documentation of the
StatsMailerextension. (#5199, #5217)Documented
TextResponse.urljoin. (#1582)Added the
body_lengthparameter to the documented signature of theheaders_receivedsignal. (#5270)Clarified
SelectorList.getusage in the tutorial. (#5256)The documentation now features the shortest import path of classes with multiple import paths. (#2733, #5099)
quotes.toscrape.comreferences now use HTTPS instead of HTTP. (#5395, #5396)Added a link to our Discord server to Getting help. (#5421, #5422)
The pronunciation of the project name is now officially /ˈskreɪpaɪ/. (#5280, #5281)
Fixed issues and implemented minor improvements. (#3155, #4335, #5074, #5098, #5134, #5180, #5194, #5239, #5266, #5271, #5273, #5274, #5276, #5347, #5356, #5414, #5415, #5416, #5419, #5420)
Quality Assurance
Significantly reduced memory usage by
scrapy.utils.response.response_httprepr(), used by theDownloaderStatsdownloader middleware, which is enabled by default. (#4964, #4972)Removed uses of the deprecated
optparsemodule. (#5366, #5374)Extended typing hints. (#5077, #5090, #5100, #5108, #5171, #5215, #5334)
Improved tests, fixed CI issues, removed unused code. (#5094, #5157, #5162, #5198, #5207, #5208, #5229, #5298, #5299, #5310, #5316, #5333, #5388, #5389, #5400, #5401, #5404, #5405, #5407, #5410, #5412, #5425, #5427)
Implemented improvements for contributors. (#5080, #5082, #5177, #5200)
Implemented cleanups. (#5095, #5106, #5209, #5228, #5235, #5245, #5246, #5292, #5314, #5322)
Scrapy 2.5.1 (2021-10-05)
Security bug fix:
If you use
HttpAuthMiddleware(i.e. thehttp_userandhttp_passspider attributes) for HTTP authentication, any request exposes your credentials to the request target.To prevent unintended exposure of authentication credentials to unintended domains, you must now additionally set a new, additional spider attribute,
http_auth_domain, and point it to the specific domain to which the authentication credentials must be sent.If the
http_auth_domainspider attribute is not set, the domain of the first request will be considered the HTTP authentication target, and authentication credentials will only be sent in requests targeting that domain.If you need to send the same HTTP authentication credentials to multiple domains, you can use
w3lib.http.basic_auth_header()instead to set the value of theAuthorizationheader of your requests.If you really want your spider to send the same HTTP authentication credentials to any domain, set the
http_auth_domainspider attribute toNone.Finally, if you are a user of scrapy-splash, know that this version of Scrapy breaks compatibility with scrapy-splash 0.7.2 and earlier. You will need to upgrade scrapy-splash to a greater version for it to continue to work.
Scrapy 2.5.0 (2021-04-06)
Highlights:
Official Python 3.9 support
Experimental HTTP/2 support
New
get_retry_request()function to retry requests from spider callbacksNew
headers_receivedsignal that allows stopping downloads earlyNew
Response.protocolattribute
Deprecation removals
Removed all code that was deprecated in 1.7.0 and had not already been removed in 2.4.0. (#4901)
Removed support for the
SCRAPY_PICKLED_SETTINGS_TO_OVERRIDEenvironment variable, deprecated in 1.8.0. (#4912)
Deprecations
The
scrapy.utils.py36module is now deprecated in favor ofscrapy.utils.asyncgen. (#4900)
New features
Experimental HTTP/2 support through a new download handler that can be assigned to the
httpsprotocol in theDOWNLOAD_HANDLERSsetting. (#1854, #4769, #5058, #5059, #5066)The new
scrapy.downloadermiddlewares.retry.get_retry_request()function may be used from spider callbacks or middlewares to handle the retrying of a request beyond the scenarios thatRetryMiddlewaresupports. (#3590, #3685, #4902)The new
headers_receivedsignal gives early access to response headers and allows stopping downloads. (#1772, #4897)The new
Response.protocolattribute gives access to the string that identifies the protocol used to download a response. (#4878)Stats now include the following entries that indicate the number of successes and failures in storing feeds:
feedexport/success_count/<storage type> feedexport/failed_count/<storage type>
Where
<storage type>is the feed storage backend class name, such asFileFeedStorageorFTPFeedStorage.The
UrlLengthMiddlewarespider middleware now logs ignored URLs withINFOlogging level instead ofDEBUG, and it now includes the following entry into stats to keep track of the number of ignored URLs:urllength/request_ignored_count
(#5036)
The
HttpCompressionMiddlewaredownloader middleware now logs the number of decompressed responses and the total count of resulting bytes:httpcompression/response_bytes httpcompression/response_count
Bug fixes
Fixed installation on PyPy installing PyDispatcher in addition to PyPyDispatcher, which could prevent Scrapy from working depending on which package got imported. (#4710, #4814)
When inspecting a callback to check if it is a generator that also returns a value, an exception is no longer raised if the callback has a docstring with lower indentation than the following code. (#4477, #4935)
The Content-Length header is no longer omitted from responses when using the default, HTTP/1.1 download handler (see
DOWNLOAD_HANDLERS). (#5009, #5034, #5045, #5057, #5062)Setting the
handle_httpstatus_allrequest meta key toFalsenow has the same effect as not setting it at all, instead of having the same effect as setting it toTrue. (#3851, #4694)
Documentation
Added instructions to install Scrapy in Windows using pip. (#4715, #4736)
Logging documentation now includes additional ways to filter logs. (#4216, #4257, #4965)
Covered how to deal with long lists of allowed domains in the FAQ. (#2263, #3667)
Covered scrapy-bench in Benchmarking. (#4996, #5016)
Clarified that one extension instance is created per crawler. (#5014)
Fixed some errors in examples. (#4829, #4830, #4907, #4909, #5008)
Fixed some external links, typos, and so on. (#4892, #4899, #4936, #4942, #5005, #5063)
The list of Request.meta keys is now sorted alphabetically. (#5061, #5065)
Updated references to Scrapinghub, which is now called Zyte. (#4973, #5072)
Added a mention to contributors in the README. (#4956)
Reduced the top margin of lists. (#4974)
Quality Assurance
Extended typing hints (#4895)
Fixed deprecated uses of the Twisted API. (#4940, #4950, #5073)
Made our tests run with the new pip resolver. (#4710, #4814)
Added tests to ensure that coroutine support is tested. (#4987)
Migrated from Travis CI to GitHub Actions. (#4924)
Implemented code refactorings, style fixes and cleanups. (#4911, #4982, #5001, #5002, #5076)
Scrapy 2.4.1 (2020-11-17)
Fixed feed exports overwrite support (#4845, #4857, #4859)
Fixed the AsyncIO event loop handling, which could make code hang (#4855, #4872)
Fixed the IPv6-capable DNS resolver
CachingHostnameResolverfor download handlers that callreactor.resolve(#4802, #4803)Fixed the output of the
genspidercommand showing placeholders instead of the import path of the generated spider module (#4874)Migrated Windows CI from Azure Pipelines to GitHub Actions (#4869, #4876)
Scrapy 2.4.0 (2020-10-11)
Highlights:
Python 3.5 support has been dropped.
The
file_pathmethod of media pipelines can now access the source item.This allows you to set a download file path based on item data.
The new
item_export_kwargskey of theFEEDSsetting allows to define keyword parameters to pass to item exporter classesYou can now choose whether feed exports overwrite or append to the output file.
For example, when using the
crawlorrunspidercommands, you can use the-Ooption instead of-oto overwrite the output file.Zstd-compressed responses are now supported if zstandard is installed.
In settings, where the import path of a class is required, it is now possible to pass a class object instead.
Modified requirements
Python 3.6 or greater is now required; support for Python 3.5 has been dropped
As a result:
When using PyPy, PyPy 7.2.0 or greater is now required
For Amazon S3 storage support in feed exports or media pipelines, botocore 1.4.87 or greater is now required
To use the images pipeline, Pillow 4.0.0 or greater is now required
Backward-incompatible changes
CookiesMiddlewareonce again discards cookies defined inRequest.headers.We decided to revert this bug fix, introduced in Scrapy 2.2.0, because it was reported that the current implementation could break existing code.
If you need to set cookies for a request, use the
Request.cookiesparameter.A future version of Scrapy will include a new, better implementation of the reverted bug fix.
Deprecation removals
scrapy.extensions.feedexport.S3FeedStorageno longer reads the values ofaccess_keyandsecret_keyfrom the running project settings when they are not passed to its__init__method; you must either pass those parameters to its__init__method or useS3FeedStorage.from_crawler(#4356, #4411, #4688)Rule.process_requestno longer admits callables which expect a singlerequestparameter, rather than bothrequestandresponse(#4818)
Deprecations
In custom media pipelines, signatures that do not accept a keyword-only
itemparameter in any of the methods that now support this parameter are now deprecated (#4628, #4686)In custom feed storage backend classes,
__init__method signatures that do not accept a keyword-onlyfeed_optionsparameter are now deprecated (#547, #716, #4512)The
scrapy.utils.python.WeakKeyCacheclass is now deprecated (#4684, #4701)The
scrapy.utils.boto.is_botocore()function is now deprecated, usescrapy.utils.boto.is_botocore_available()instead (#4734, #4776)
New features
The following methods of media pipelines now accept an
itemkeyword-only parameter containing the source item:In
scrapy.pipelines.files.FilesPipeline:file_downloaded()media_downloaded()media_to_download()
In
scrapy.pipelines.images.ImagesPipeline:file_downloaded()get_images()image_downloaded()media_downloaded()media_to_download()
The new
item_export_kwargskey of theFEEDSsetting allows to define keyword parameters to pass to item exporter classes (#4606, #4768)Feed exports gained overwrite support:
When using the
crawlorrunspidercommands, you can use the-Ooption instead of-oto overwrite the output fileYou can use the
overwritekey in theFEEDSsetting to configure whether to overwrite the output file (True) or append to its content (False)The
__init__andfrom_crawlermethods of feed storage backend classes now receive a new keyword-only parameter,feed_options, which is a dictionary of feed options
Zstd-compressed responses are now supported if zstandard is installed (#4831)
In settings, where the import path of a class is required, it is now possible to pass a class object instead (#3870, #3873).
This includes also settings where only part of its value is made of an import path, such as
DOWNLOADER_MIDDLEWARESorDOWNLOAD_HANDLERS.Downloader middlewares can now override
response.request.If a downloader middleware returns a
Responseobject fromprocess_response()orprocess_exception()with a customRequestobject assigned toresponse.request:The response is handled by the callback of that custom
Requestobject, instead of being handled by the callback of the originalRequestobjectThat custom
Requestobject is now sent as therequestargument to theresponse_receivedsignal, instead of the originalRequestobject
When using the FTP feed storage backend:
It is now possible to set the new
overwritefeed option toFalseto append to an existing file instead of overwriting itThe FTP password can now be omitted if it is not necessary
The
__init__method ofCsvItemExporternow supports anerrorsparameter to indicate how to handle encoding errors (#4755)When using asyncio, it is now possible to set a custom asyncio loop (#4306, #4414)
Serialized requests (see Jobs: pausing and resuming crawls) now support callbacks that are spider methods that delegate on other callable (#4756)
When a response is larger than
DOWNLOAD_MAXSIZE, the logged message is now a warning, instead of an error (#3874, #3886, #4752)
Bug fixes
The
genspidercommand no longer overwrites existing files unless the--forceoption is used (#4561, #4616, #4623)Cookies with an empty value are no longer considered invalid cookies (#4772)
The
runspidercommand now supports files with the.pywfile extension (#4643, #4646)The
HttpProxyMiddlewaremiddleware now simply ignores unsupported proxy values (#3331, #4778)Checks for generator callbacks with a
returnstatement no longer warn aboutreturnstatements in nested functions (#4720, #4721)The system file mode creation mask no longer affects the permissions of files generated using the
startprojectcommand (#4722)scrapy.utils.iterators.xmliternow supports namespaced node names (#861, #4746)Requestobjects can now haveabout:URLs, which can work when using a headless browser (#4835)
Documentation
The
FEED_URI_PARAMSsetting is now documented (#4671, #4724)Improved the documentation of link extractors with an usage example from a spider callback and reference documentation for the
Linkclass (#4751, #4775)Clarified the impact of
CONCURRENT_REQUESTSwhen using theCloseSpiderextension (#4836)Removed references to Python 2’s
unicodetype (#4547, #4703)We now have an official deprecation policy (#4705)
Our documentation policies now cover usage of Sphinx’s
versionaddedandversionchangeddirectives, and we have removed usages referencing Scrapy 1.4.0 and earlier versions (#3971, #4310)Other documentation cleanups (#4090, #4782, #4800, #4801, #4809, #4816, #4825)
Quality assurance
Scrapy 2.3.0 (2020-08-04)
Highlights:
Feed exports now support Google Cloud Storage as a storage backend
The new
FEED_EXPORT_BATCH_ITEM_COUNTsetting allows to deliver output items in batches of up to the specified number of items.It also serves as a workaround for delayed file delivery, which causes Scrapy to only start item delivery after the crawl has finished when using certain storage backends (S3, FTP, and now GCS).
The base implementation of item loaders has been moved into a separate library, itemloaders, allowing usage from outside Scrapy and a separate release schedule
Deprecation removals
Removed the following classes and their parent modules from
scrapy.linkextractors:htmlparser.HtmlParserLinkExtractorregex.RegexLinkExtractorsgml.BaseSgmlLinkExtractorsgml.SgmlLinkExtractor
Use
LinkExtractorinstead (#4356, #4679)
Deprecations
The
scrapy.utils.python.retry_on_eintrfunction is now deprecated (#4683)
New features
Feed exports support Google Cloud Storage (#685, #3608)
New
FEED_EXPORT_BATCH_ITEM_COUNTsetting for batch deliveries (#4250, #4434)The
parsecommand now allows specifying an output file (#4317, #4377)Request.from_curl()andcurl_to_request_kwargs()now also support--data-raw(#4612)A
parsecallback may now be used in built-in spider subclasses, such asCrawlSpider(#712, #732, #781, #4254 )
Bug fixes
Fixed the CSV exporting of dataclass items and attr.s items (#4667, #4668)
Request.from_curl()andcurl_to_request_kwargs()now set the request method toPOSTwhen a request body is specified and no request method is specified (#4612)The processing of ANSI escape sequences in enabled in Windows 10.0.14393 and later, where it is required for colored output (#4393, #4403)
Documentation
Updated the OpenSSL cipher list format link in the documentation about the
DOWNLOADER_CLIENT_TLS_CIPHERSsetting (#4653)Simplified the code example in Working with dataclass items (#4652)
Quality assurance
The base implementation of item loaders has been moved into itemloaders (#4005, #4516)
Fixed a silenced error in some scheduler tests (#4644, #4645)
Renewed the localhost certificate used for SSL tests (#4650)
Removed cookie-handling code specific to Python 2 (#4682)
Stopped using Python 2 unicode literal syntax (#4704)
Stopped using a backlash for line continuation (#4673)
Removed unneeded entries from the MyPy exception list (#4690)
Automated tests now pass on Windows as part of our continuous integration system (#4458)
Automated tests now pass on the latest PyPy version for supported Python versions in our continuous integration system (#4504)
Scrapy 2.2.1 (2020-07-17)
The
startprojectcommand no longer makes unintended changes to the permissions of files in the destination folder, such as removing execution permissions (#4662, #4666)
Scrapy 2.2.0 (2020-06-24)
Highlights:
Python 3.5.2+ is required now
dataclass objects and attrs objects are now valid item types
New
TextResponse.jsonmethodNew
bytes_receivedsignal that allows canceling response downloadCookiesMiddlewarefixes
Backward-incompatible changes
Support for Python 3.5.0 and 3.5.1 has been dropped; Scrapy now refuses to run with a Python version lower than 3.5.2, which introduced
typing.Type(#4615)
Deprecations
TextResponse.body_as_unicode()is now deprecated, useTextResponse.textinstead (#4546, #4555, #4579)scrapy.item.BaseItemis now deprecated, usescrapy.item.Iteminstead (#4534)
New features
dataclass objects and attrs objects are now valid item types, and a new itemadapter library makes it easy to write code that supports any item type (#2749, #2807, #3761, #3881, #4642)
A new
TextResponse.jsonmethod allows to deserialize JSON responses (#2444, #4460, #4574)A new
bytes_receivedsignal allows monitoring response download progress and stopping downloads (#4205, #4559)The dictionaries in the result list of a media pipeline now include a new key,
status, which indicates if the file was downloaded or, if the file was not downloaded, why it was not downloaded; seeFilesPipeline.get_media_requestsfor more information (#2893, #4486)When using Google Cloud Storage for a media pipeline, a warning is now logged if the configured credentials do not grant the required permissions (#4346, #4508)
Link extractors are now serializable, as long as you do not use lambdas for parameters; for example, you can now pass link extractors in
Request.cb_kwargsorRequest.metawhen persisting scheduled requests (#4554)Upgraded the pickle protocol that Scrapy uses from protocol 2 to protocol 4, improving serialization capabilities and performance (#4135, #4541)
scrapy.utils.misc.create_instance()now raises aTypeErrorexception if the resulting instance isNone(#4528, #4532)
Bug fixes
CookiesMiddlewareno longer discards cookies defined inRequest.headers(#1992, #2400)CookiesMiddlewareno longer re-encodes cookies defined asbytesin thecookiesparameter of the__init__method ofRequest(#2400, #3575)When
FEEDSdefines multiple URIs,FEED_STORE_EMPTYisFalseand the crawl yields no items, Scrapy no longer stops feed exports after the first URI (#4621, #4626)Spidercallbacks defined using coroutine syntax no longer need to return an iterable, and may instead return aRequestobject, an item, orNone(#4609)The
startprojectcommand now ensures that the generated project folders and files have the right permissions (#4604)Fix a
KeyErrorexception being sometimes raised fromscrapy.utils.datatypes.LocalWeakReferencedCache(#4597, #4599)When
FEEDSdefines multiple URIs, log messages about items being stored now contain information from the corresponding feed, instead of always containing information about only one of the feeds (#4619, #4629)
Documentation
Added a new section about accessing cb_kwargs from errbacks (#4598, #4634)
Covered chompjs in Parsing JavaScript code (#4556, #4562)
Removed from Coroutines the warning about the API being experimental (#4511, #4513)
Removed references to unsupported versions of Twisted (#4533)
Updated the description of the screenshot pipeline example, which now uses coroutine syntax instead of returning a
Deferred(#4514, #4593)Removed a misleading import line from the
scrapy.utils.log.configure_logging()code example (#4510, #4587)The display-on-hover behavior of internal documentation references now also covers links to commands,
Request.metakeys, settings and signals (#4495, #4563)It is again possible to download the documentation for offline reading (#4578, #4585)
Removed backslashes preceding
*argsand**kwargsin some function and method signatures (#4592, #4596)
Quality assurance
Adjusted the code base further to our style guidelines (#4237, #4525, #4538, #4539, #4540, #4542, #4543, #4544, #4545, #4557, #4558, #4566, #4568, #4572)
Improved code sharing between the
crawlandrunspidercommands (#4548, #4552)Replaced
chain(*iterable)withchain.from_iterable(iterable)(#4635)You may now run the
asynciotests with Tox on any Python version (#4521)Updated test requirements to reflect an incompatibility with pytest 5.4 and 5.4.1 (#4588)
Improved
SpiderLoadertest coverage for scenarios involving duplicate spider names (#4549, #4560)Configured Travis CI to also run the tests with Python 3.5.2 (#4518, #4615)
Made use of set literals in tests (#4573)
Cleaned up the Travis CI configuration (#4517, #4519, #4522, #4537)
Scrapy 2.1.0 (2020-04-24)
Highlights:
New
FEEDSsetting to export to multiple feedsNew
Response.ip_addressattribute
Backward-incompatible changes
AssertionErrorexceptions triggered by assert statements have been replaced by new exception types, to support running Python in optimized mode (see-O) without changing Scrapy’s behavior in any unexpected ways.If you catch an
AssertionErrorexception from Scrapy, update your code to catch the corresponding new exception.(#4440)
Deprecation removals
The
LOG_UNSERIALIZABLE_REQUESTSsetting is no longer supported, useSCHEDULER_DEBUGinstead (#4385)The
REDIRECT_MAX_METAREFRESH_DELAYsetting is no longer supported, useMETAREFRESH_MAXDELAYinstead (#4385)The
ChunkedTransferMiddlewaremiddleware has been removed, including the entirescrapy.downloadermiddlewares.chunkedmodule; chunked transfers work out of the box (#4431)The
spidersproperty has been removed fromCrawler, useCrawlerRunner.spider_loaderor instantiateSPIDER_LOADER_CLASSwith your settings instead (#4398)The
MultiValueDict,MultiValueDictKeyError, andSiteNodeclasses have been removed fromscrapy.utils.datatypes(#4400)
Deprecations
New features
A new setting,
FEEDS, allows configuring multiple output feeds with different settings each (#1336, #3858, #4507)The
crawlandrunspidercommands now support multiple-oparameters (#1336, #3858, #4507)The
crawlandrunspidercommands now support specifying an output format by appending:<format>to the output file (#1336, #3858, #4507)The new
Response.ip_addressattribute gives access to the IP address that originated a response (#3903, #3940)A warning is now issued when a value in
allowed_domainsincludes a port (#50, #3198, #4413)Zsh completion now excludes used option aliases from the completion list (#4438)
Bug fixes
Request serialization no longer breaks for callbacks that are spider attributes which are assigned a function with a different name (#4500)
Nonevalues inallowed_domainsno longer cause aTypeErrorexception (#4410)Zsh completion no longer allows options after arguments (#4438)
zope.interface 5.0.0 and later versions are now supported (#4447, #4448)
Spider.make_requests_from_url, deprecated in Scrapy 1.4.0, now issues a warning when used (#4412)
Documentation
Improved the documentation about signals that allow their handlers to return a
Deferred(#4295, #4390)Our PyPI entry now includes links for our documentation, our source code repository and our issue tracker (#4456)
Covered the curl2scrapy service in the documentation (#4206, #4455)
Removed references to the Guppy library, which only works in Python 2 (#4285, #4343)
Extended use of InterSphinx to link to Python 3 documentation (#4444, #4445)
Added support for Sphinx 3.0 and later (#4475, #4480, #4496, #4503)
Quality assurance
Removed warnings about using old, removed settings (#4404)
Removed a warning about importing
StringTransportfromtwisted.test.proto_helpersin Twisted 19.7.0 or newer (#4409)Removed outdated Debian package build files (#4384)
Removed code that added support for old versions of Twisted that we no longer support (#4472)
Removed
twisted.internet.defer.returnValue()calls (#4443, #4446, #4489)
Scrapy 2.0.1 (2020-03-18)
Scrapy 2.0.0 (2020-03-03)
Highlights:
Python 2 support has been removed
Partial coroutine syntax support and experimental
asynciosupportNew
Response.follow_allmethodFTP support for media pipelines
New
Response.certificateattributeIPv6 support through
DNS_RESOLVER
Backward-incompatible changes
Python 2 support has been removed, following Python 2 end-of-life on January 1, 2020 (#4091, #4114, #4115, #4121, #4138, #4231, #4242, #4304, #4309, #4373)
Retry gaveups (see
RETRY_TIMES) are now logged as errors instead of as debug information (#3171, #3566)File extensions that
LinkExtractorignores by default now also include7z,7zip,apk,bz2,cdr,dmg,ico,iso,tar,tar.gz,webm, andxz(#1837, #2067, #4066)The
METAREFRESH_IGNORE_TAGSsetting is now an empty list by default, following web browser behavior (#3844, #4311)The
HttpCompressionMiddlewarenow includes spaces after commas in the value of theAccept-Encodingheader that it sets, following web browser behavior (#4293)The
__init__method of custom download handlers (seeDOWNLOAD_HANDLERS) or subclasses of the following downloader handlers no longer receives asettingsparameter:Use the
from_settingsorfrom_crawlerclass methods to expose such a parameter to your custom download handlers.(#4126)
We have refactored the
scrapy.core.scheduler.Schedulerclass and related queue classes (seeSCHEDULER_PRIORITY_QUEUE,SCHEDULER_DISK_QUEUEandSCHEDULER_MEMORY_QUEUE) to make it easier to implement custom scheduler queue classes. See Changes to scheduler queue classes below for details.Overridden settings are now logged in a different format. This is more in line with similar information logged at startup (#4199)
Deprecation removals
The Scrapy shell no longer provides a sel proxy object, use
response.selectorinstead (#4347)LevelDB support has been removed (#4112)
The following functions have been removed from
scrapy.utils.python:isbinarytext,is_writable,setattr_default,stringify_dict(#4362)
Deprecations
Using environment variables prefixed with
SCRAPY_to override settings is deprecated (#4300, #4374, #4375)scrapy.linkextractors.FilteringLinkExtractoris deprecated, usescrapy.linkextractors.LinkExtractorinstead (#4045)The
noconnectquery string argument of proxy URLs is deprecated and should be removed from proxy URLs (#4198)The
nextmethod ofscrapy.utils.python.MutableChainis deprecated, use the globalnext()function orMutableChain.__next__instead (#4153)
New features
Added partial support for Python’s coroutine syntax and experimental support for
asyncioandasyncio-powered libraries (#4010, #4259, #4269, #4270, #4271, #4316, #4318)The new
Response.follow_allmethod offers the same functionality asResponse.followbut supports an iterable of URLs as input and returns an iterable of requests (#2582, #4057, #4286)Media pipelines now support FTP storage (#3928, #3961)
The new
Response.certificateattribute exposes the SSL certificate of the server as atwisted.internet.ssl.Certificateobject for HTTPS responses (#2726, #4054)A new
DNS_RESOLVERsetting allows enabling IPv6 support (#1031, #4227)A new
SCRAPER_SLOT_MAX_ACTIVE_SIZEsetting allows configuring the existing soft limit that pauses request downloads when the total response data being processed is too high (#1410, #3551)A new
TWISTED_REACTORsetting allows customizing thereactorthat Scrapy uses, allowing to enable asyncio support or deal with a common macOS issue (#2905, #4294)Scheduler disk and memory queues may now use the class methods
from_crawlerorfrom_settings(#3884)The new
Response.cb_kwargsattribute serves as a shortcut forResponse.request.cb_kwargs(#4331)Response.follownow supports aflagsparameter, for consistency withRequest(#4277, #4279)Item loader processors can now be regular functions, they no longer need to be methods (#3899)
Requestno longer requires acallbackparameter when anerrbackparameter is specified (#3586, #4008)LogFormatternow supports some additional methods:download_errorfor download errorsitem_errorfor exceptions raised during item processing by item pipelinesspider_errorfor exceptions raised from spider callbacks
The
FEED_URIsetting now supportspathlib.Pathvalues (#3731, #4074)A new
request_left_downloadersignal is sent when a request leaves the downloader (#4303)Scrapy logs a warning when it detects a request callback or errback that uses
yieldbut also returns a value, since the returned value would be lost (#3484, #3869)Spiderobjects now raise anAttributeErrorexception if they do not have astart_urlsattribute nor reimplementscrapy.spiders.Spider.start_requests(), but have astart_urlattribute (#4133, #4170)BaseItemExportersubclasses may now usesuper().__init__(**kwargs)instead ofself._configure(kwargs)in their__init__method, passingdont_fail=Trueto the parent__init__method if needed, and accessingkwargsatself._kwargsafter calling their parent__init__method (#4193, #4370)A new
keep_fragmentsparameter ofscrapy.utils.request.request_fingerprintallows to generate different fingerprints for requests with different fragments in their URL (#4104)Download handlers (see
DOWNLOAD_HANDLERS) may now use thefrom_settingsandfrom_crawlerclass methods that other Scrapy components already supported (#4126)scrapy.utils.python.MutableChain.__iter__now returnsself, allowing it to be used as a sequence. (#4153)
Bug fixes
The
crawlcommand now also exits with exit code 1 when an exception happens before the crawling starts (#4175, #4207)LinkExtractor.extract_linksno longer re-encodes the query string or URLs from non-UTF-8 responses in UTF-8 (#998, #1403, #1949, #4321)The first spider middleware (see
SPIDER_MIDDLEWARES) now also processes exceptions raised from callbacks that are generators (#4260, #4272)Redirects to URLs starting with 3 slashes (
///) are now supported (#4032, #4042)Requestno longer accepts strings asurlsimply because they have a colon (#2552, #4094)The correct encoding is now used for attach names in
MailSender(#4229, #4239)RFPDupeFilter, the defaultDUPEFILTER_CLASS, no longer writes an extra\rcharacter on each line in Windows, which made the size of therequests.seenfile unnecessarily large on that platform (#4283)Z shell auto-completion now looks for
.htmlfiles, not.httpfiles, and covers the-hcommand-line switch (#4122, #4291)Adding items to a
scrapy.utils.datatypes.LocalCacheobject without alimitdefined no longer raises aTypeErrorexception (#4123)Fixed a typo in the message of the
ValueErrorexception raised whenscrapy.utils.misc.create_instance()gets bothsettingsandcrawlerset toNone(#4128)
Documentation
API documentation now links to an online, syntax-highlighted view of the corresponding source code (#4148)
Links to unexisting documentation pages now allow access to the sidebar (#4152, #4169)
Cross-references within our documentation now display a tooltip when hovered (#4173, #4183)
Improved the documentation about
LinkExtractor.extract_linksand simplified Link Extractors (#4045)Clarified how
ItemLoader.itemworks (#3574, #4099)Clarified that
logging.basicConfig()should not be used when also usingCrawlerProcess(#2149, #2352, #3146, #3960)Clarified the requirements for
Requestobjects when using persistence (#4124, #4139)Clarified how to install a custom image pipeline (#4034, #4252)
Fixed the signatures of the
file_pathmethod in media pipeline examples (#4290)Covered a backward-incompatible change in Scrapy 1.7.0 affecting custom
scrapy.core.scheduler.Schedulersubclasses (#4274)Improved the
README.rstandCODE_OF_CONDUCT.mdfiles (#4059)Documentation examples are now checked as part of our test suite and we have fixed some of the issues detected (#4142, #4146, #4171, #4184, #4190)
Fixed logic issues, broken links and typos (#4247, #4258, #4282, #4288, #4305, #4308, #4323, #4338, #4359, #4361)
Improved consistency when referring to the
__init__method of an object (#4086, #4088)Fixed an inconsistency between code and output in Scrapy at a glance (#4213)
Extended
intersphinxusage (#4147, #4172, #4185, #4194, #4197)We now use a recent version of Python to build the documentation (#4140, #4249)
Quality assurance
Added Bandit security checks to our test suite (#4162, #4181)
Added Flake8 style checks to our test suite and applied many of the corresponding changes (#3944, #3945, #4137, #4157, #4167, #4174, #4186, #4195, #4238, #4246, #4355, #4360, #4365)
Started reporting slowest tests, and improved the performance of some of them (#4163, #4164)
Fixed broken tests and refactored some tests (#4014, #4095, #4244, #4268, #4372)
Modified the tox configuration to allow running tests with any Python version, run Bandit and Flake8 tests by default, and enforce a minimum tox version programmatically (#4179)
Cleaned up code (#3937, #4208, #4209, #4210, #4212, #4369, #4376, #4378)
Changes to scheduler queue classes
The following changes may impact any custom queue classes of all types:
The
pushmethod no longer receives a second positional parameter containingrequest.priority * -1. If you need that value, get it from the first positional parameter,request, instead, or use the newpriority()method inscrapy.core.scheduler.ScrapyPriorityQueuesubclasses.
The following changes may impact custom priority queue classes:
In the
__init__method or thefrom_crawlerorfrom_settingsclass methods:The parameter that used to contain a factory function,
qfactory, is now passed as a keyword parameter nameddownstream_queue_cls.A new keyword parameter has been added:
key. It is a string that is always an empty string for memory queues and indicates theJOBDIRvalue for disk queues.The parameter for disk queues that contains data from the previous crawl,
startpriosorslot_startprios, is now passed as a keyword parameter namedstartprios.The
serializeparameter is no longer passed. The disk queue class must take care of request serialization on its own before writing to disk, using therequest_to_dict()andrequest_from_dict()functions from thescrapy.utils.reqsermodule.
The following changes may impact custom disk and memory queue classes:
The signature of the
__init__method is now__init__(self, crawler, key).
The following changes affect specifically the
ScrapyPriorityQueue and
DownloaderAwarePriorityQueue classes from
scrapy.core.scheduler and may affect subclasses:
In the
__init__method, most of the changes described above apply.__init__may still receive all parameters as positional parameters, however:downstream_queue_cls, which replacedqfactory, must be instantiated differently.qfactorywas instantiated with a priority value (integer).Instances of
downstream_queue_clsshould be created using the newScrapyPriorityQueue.qfactoryorDownloaderAwarePriorityQueue.pqfactorymethods.The new
keyparameter displaced thestartpriosparameter 1 position to the right.
The following class attributes have been added:
crawlerdownstream_queue_cls(details above)key(details above)
The
serializeattribute has been removed (details above)
The following changes affect specifically the
ScrapyPriorityQueue class and may affect
subclasses:
A new
priority()method has been added which, given a request, returnsrequest.priority * -1.It is used in
push()to make up for the removal of itspriorityparameter.The
spiderattribute has been removed. Usecrawler.spiderinstead.
The following changes affect specifically the
DownloaderAwarePriorityQueue class and may
affect subclasses:
A new
pqueuesattribute offers a mapping of downloader slot names to the corresponding instances ofdownstream_queue_cls.
(#3884)