This commit is contained in:
Rishikeshan 2026-07-13 12:51:12 -05:00 committed by GitHub
commit 6ec062242b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
84 changed files with 40 additions and 461 deletions

View File

@ -378,6 +378,27 @@ This handler supports ``ftp://host/path`` FTP URIs.
It's implemented using :mod:`twisted.protocols.ftp`.
.. _topics-ftp-request-meta:
FTP connection parameters can be passed using :attr:`Request.meta
<scrapy.Request.meta>`:
* ``ftp_user`` (falls back to :setting:`FTP_USER`)
* ``ftp_password`` (falls back to :setting:`FTP_PASSWORD`)
* ``ftp_passive`` (falls back to :setting:`FTP_PASSIVE_MODE`)
* ``ftp_local_filename``: if not given, file data is returned in
``response.body``. If given, file data is saved to that local path (useful
for large files) and the local filename is also returned in ``response.body``.
The built response uses HTTP-like status codes by default: ``200`` on success,
``404`` when the file is not found (FTP code 550), or the corresponding FTP
exception otherwise. The mapping from FTP return codes to response status codes
is defined in the :attr:`~scrapy.core.downloader.handlers.ftp.FTPDownloadHandler.CODE_MAPPING`
class attribute. The ``default`` key is used for unmapped codes.
On successful requests (status 200), ``response.headers`` includes
``Local Filename`` (when ``ftp_local_filename`` is used) and ``Size``.
S3DownloadHandler
-----------------

View File

@ -721,6 +721,8 @@ Those are:
* :reqmeta:`download_warnsize`
* :reqmeta:`download_timeout`
* ``ftp_password`` (See :setting:`FTP_PASSWORD` for more info)
* ``ftp_passive`` (See :setting:`FTP_PASSIVE_MODE` for more info)
* ``ftp_local_filename`` (See :ref:`topics-ftp-request-meta` for more info)
* ``ftp_user`` (See :setting:`FTP_USER` for more info)
* :reqmeta:`give_up_log_level`
* :reqmeta:`handle_httpstatus_all`

View File

@ -1,7 +1,3 @@
"""
Scrapy - a web crawling and web scraping framework written for Python
"""
import pkgutil
import sys
import warnings

View File

@ -1,7 +1,3 @@
"""
Base class for Scrapy commands
"""
from __future__ import annotations
import argparse

View File

@ -1,9 +1,3 @@
"""
Scrapy Shell
See documentation in docs/topics/shell.rst
"""
from __future__ import annotations
import asyncio

View File

@ -1,3 +0,0 @@
"""
Scrapy core library classes and functions.
"""

View File

@ -1,5 +1,3 @@
"""Download handlers for different schemes"""
from __future__ import annotations
import inspect

View File

@ -1,5 +1,3 @@
"""``httpx``-based HTTP(S) download handler. Currently not recommended for production use."""
from __future__ import annotations
import ipaddress

View File

@ -1,33 +1,3 @@
"""
An asynchronous FTP file download handler for scrapy which somehow emulates an http response.
FTP connection parameters are passed using the request meta field:
- ftp_user (optional, falls back to FTP_USER)
- ftp_password (optional, falls back to FTP_PASSWORD)
- ftp_passive (optional, falls back to FTP_PASSIVE_MODE) sets FTP connection passive mode
- ftp_local_filename
- If not given, file data will come in the response.body, as a normal scrapy Response,
which will imply that the entire file will be on memory.
- if given, file data will be saved in a local file with the given name
This helps when downloading very big files to avoid memory issues. In addition, for
convenience the local file name will also be given in the response body.
The status of the built html response will be, by default
- 200 in case of success
- 404 in case specified file was not found in the server (ftp code 550)
or raise corresponding ftp exception otherwise
The matching from server ftp command return codes to html response codes is defined in the
CODE_MAPPING attribute of the handler class. The key 'default' is used for any code
that is not explicitly present among the map keys. You may need to overwrite this
mapping if want a different behaviour than default.
In case of status 200 request, response.headers will come with two keys:
'Local Filename' - with the value of the local filename if given
'Size' - with size of the downloaded data
"""
from __future__ import annotations
import re

View File

@ -1,5 +1,3 @@
"""Download handlers for http and https schemes"""
from __future__ import annotations
import ipaddress

View File

@ -1,9 +1,3 @@
"""
Downloader Middleware manager
See documentation in docs/topics/downloader-middleware.rst
"""
from __future__ import annotations
import warnings

View File

@ -1,10 +1,3 @@
"""
This is the Scrapy engine which controls the Scheduler, Downloader and Spider.
For more information see docs/topics/architecture.rst
"""
from __future__ import annotations
import asyncio

View File

@ -1,6 +1,3 @@
"""This module implements the Scraper component which parses responses and
extracts information from them"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
Spider Middleware manager
See documentation in docs/topics/spider-middleware.rst
"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
DefaultHeaders downloader middleware
See documentation in docs/topics/downloader-middleware.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING

View File

@ -1,9 +1,3 @@
"""
Download timeout middleware
See documentation in docs/topics/downloader-middleware.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING

View File

@ -1,9 +1,3 @@
"""
HTTP basic auth downloader middleware
See documentation in docs/topics/downloader-middleware.rst
"""
from __future__ import annotations
import warnings

View File

@ -1,12 +1,3 @@
"""
An extension to retry failed requests that are potentially caused by temporary
problems such as a connection timeout or HTTP 500 error.
You can change the behaviour of this middleware by modifying the scraping settings:
RETRY_TIMES - how many times to retry a failed page
RETRY_HTTP_CODES - which HTTP response codes to retry
"""
from __future__ import annotations
from logging import Logger, getLevelName, getLogger

View File

@ -1,9 +1,3 @@
"""
This is a middleware to respect robots.txt policies. To activate it you must
enable this middleware and enable the ROBOTSTXT_OBEY setting.
"""
from __future__ import annotations
import logging

View File

@ -1,5 +1,3 @@
"""Set User-Agent header per spider or use a default value from settings"""
from __future__ import annotations
from typing import TYPE_CHECKING

View File

@ -1,9 +1,5 @@
"""
Scrapy core exceptions
These exceptions are documented in docs/topics/exceptions.rst. Please don't add
new exceptions here without documenting them there.
"""
# These exceptions are documented in docs/topics/exceptions.rst. Please don't add
# new exceptions here without documenting them there.
from __future__ import annotations

View File

@ -1,7 +1,3 @@
"""
Item Exporters are used to export/serialize items into different formats.
"""
from __future__ import annotations
import csv

View File

@ -1,9 +1,3 @@
"""
The Extension Manager
See documentation in docs/topics/extensions.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any

View File

@ -1,9 +1,3 @@
"""CloseSpider is an extension that forces spiders to be closed after certain
conditions are met.
See documentation in docs/topics/extensions.rst
"""
from __future__ import annotations
import logging

View File

@ -1,7 +1,3 @@
"""
Extension for collecting core stats like items scraped and start/finish times
"""
from __future__ import annotations
from datetime import datetime, timezone

View File

@ -1,9 +1,3 @@
"""
Extensions for debugging Scrapy
See documentation in docs/topics/extensions.rst
"""
from __future__ import annotations
import contextlib

View File

@ -1,9 +1,3 @@
"""
Feed Exports extension
See documentation in docs/topics/feed-exports.rst
"""
from __future__ import annotations
import asyncio

View File

@ -1,9 +1,3 @@
"""
MemoryDebugger extension
See documentation in docs/topics/extensions.rst
"""
from __future__ import annotations
import gc

View File

@ -1,9 +1,3 @@
"""
MemoryUsage extension
See documentation in docs/topics/extensions.rst
"""
from __future__ import annotations
import logging

View File

@ -1,7 +1,3 @@
"""
Extension for processing data before they are exported to feeds.
"""
from bz2 import BZ2File
from gzip import GzipFile
from io import IOBase

View File

@ -1,9 +1,3 @@
"""
StatsMailer extension sends an email when a spider finishes scraping.
Use STATSMAILER_RCPTS setting to enable and give the recipient mail address
"""
from __future__ import annotations
import warnings

View File

@ -1,9 +1,3 @@
"""
Scrapy Telnet Console extension
See documentation in docs/topics/telnetconsole.rst
"""
from __future__ import annotations
import binascii

View File

@ -1,10 +1,3 @@
"""
Module containing all HTTP related classes
Use this module (instead of the more specific ones) when importing Headers,
Request and Response outside this module.
"""
from scrapy.http.headers import Headers
from scrapy.http.request import Request
from scrapy.http.request.form import FormRequest

View File

@ -1,10 +1,3 @@
"""
This module implements the Request class which is used to represent HTTP
requests in Scrapy.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
import inspect

View File

@ -1,10 +1,3 @@
"""
This module implements the FormRequest class which is a more convenient class
(than Request) to generate Requests based on form data.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
from collections.abc import Iterable

View File

@ -1,10 +1,3 @@
"""
This module implements the JsonRequest class which is a more convenient class
(than Request) to generate JSON Requests.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
import copy

View File

@ -1,10 +1,3 @@
"""
This module implements the XmlRpcRequest class which is a more convenient class
(that Request) to generate xml-rpc requests.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
import xmlrpc.client as xmlrpclib

View File

@ -1,10 +1,3 @@
"""
This module implements the Response class which is used to represent HTTP
responses in Scrapy.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, AnyStr, TypeVar, overload

View File

@ -1,11 +1,3 @@
"""
This module implements the :class:`HtmlResponse` class which is used as a
content type marker by :class:`~scrapy.selector.Selector` and can be used in
``isinstance()`` checks.
See documentation in docs/topics/request-response.rst
"""
from scrapy.http.response.text import TextResponse

View File

@ -1,10 +1,3 @@
"""
This module implements the JsonResponse class that is used when the response
has a JSON MIME type in its Content-Type header.
See documentation in docs/topics/request-response.rst
"""
from scrapy.http.response.text import TextResponse

View File

@ -1,10 +1,3 @@
"""
This module implements the TextResponse class which adds encoding handling and
discovering (through HTTP headers) to base Response class.
See documentation in docs/topics/request-response.rst
"""
from __future__ import annotations
import json

View File

@ -1,11 +1,3 @@
"""
This module implements the :class:`XmlResponse` class which is used as a
content type marker by :class:`~scrapy.selector.Selector` and can be used in
``isinstance()`` checks.
See documentation in docs/topics/request-response.rst
"""
from scrapy.http.response.text import TextResponse

View File

@ -1,9 +1,3 @@
"""
Scrapy Item
See documentation in docs/topics/items.rst
"""
from __future__ import annotations
from abc import ABCMeta

View File

@ -1,11 +1,3 @@
"""
This module defines the Link object used in Link extractors.
For actual link extractors implementation see scrapy.linkextractors, or
its documentation in: docs/topics/link-extractors.rst
"""
class Link:
"""Link objects represent an extracted link by the LinkExtractor.

View File

@ -1,11 +1,3 @@
"""
scrapy.linkextractors
This package contains a collection of Link Extractors.
For more info see docs/topics/link-extractors.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING

View File

@ -1,7 +1,3 @@
"""
Link extractor based on lxml.html
"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
Item Loader
See documentation in docs/topics/loaders.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any

View File

@ -1,7 +1,3 @@
"""
Mail sending helpers
"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
Item pipeline
See documentation in docs/topics/item-pipeline.rst
"""
from __future__ import annotations
import asyncio

View File

@ -1,9 +1,3 @@
"""
Files Pipeline
See documentation in topics/media-pipeline.rst
"""
from __future__ import annotations
import base64

View File

@ -1,9 +1,3 @@
"""
Images Pipeline
See documentation in topics/media-pipeline.rst
"""
from __future__ import annotations
import functools

View File

@ -1,8 +1,3 @@
"""
This module implements a class which returns the appropriate Response class
based on different criteria.
"""
from __future__ import annotations
from io import StringIO

View File

@ -1,7 +1,3 @@
"""
Selectors
"""
# top-level imports
from scrapy.selector.unified import Selector, SelectorList

View File

@ -1,17 +1,10 @@
"""This module contains the default values for all settings used by Scrapy.
For more information about these settings you can read the settings
documentation in docs/topics/settings.rst
Scrapy developers, if you add a setting here remember to:
* add it in alphabetical order, with the exception that enabling flags and
other high-level settings for a group should come first in their group
and pairs like host/port and user/password should be in the usual order
* group similar settings without leaving blank lines
* add its documentation to the available settings documentation
(docs/topics/settings.rst)
"""
# Scrapy developers, if you add a setting here remember to:
#
# * add it in alphabetical order, with the exception that enabling flags and
# other high-level settings for a group should come first in their group
# and pairs like host/port and user/password should be in the usual order
# * group similar settings without leaving blank lines
# * add its documentation to docs/topics/settings.rst
import sys
from importlib import import_module

View File

@ -1,9 +1,3 @@
"""Scrapy Shell
See documentation in docs/topics/shell.rst
"""
from __future__ import annotations
import asyncio

View File

@ -1,9 +1,5 @@
"""
Scrapy signals
These signals are documented in docs/topics/signals.rst. Please don't add new
signals here without documenting them there.
"""
# These signals are documented in docs/topics/signals.rst. Please don't add new
# signals here without documenting them there.
engine_started = object()
engine_stopped = object()

View File

@ -1,9 +1,3 @@
"""
Depth Spider Middleware
See documentation in docs/topics/spider-middleware.rst
"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
HttpError Spider Middleware
See documentation in docs/topics/spider-middleware.rst
"""
from __future__ import annotations
import logging

View File

@ -1,8 +1,3 @@
"""
RefererMiddleware: populates Request referer field, based on the Response which
originated it.
"""
from __future__ import annotations
import warnings

View File

@ -1,9 +1,3 @@
"""
Url Length Spider Middleware
See documentation in docs/topics/spider-middleware.rst
"""
from __future__ import annotations
import logging

View File

@ -1,9 +1,3 @@
"""
Base class for Scrapy spiders
See documentation in docs/topics/spiders.rst
"""
from __future__ import annotations
import logging

View File

@ -1,10 +1,3 @@
"""
This modules implements the CrawlSpider which is the recommended spider to use
for scraping typical websites that requires crawling pages.
See documentation in docs/topics/spiders.rst
"""
from __future__ import annotations
import copy

View File

@ -1,10 +1,3 @@
"""
This module implements the XMLFeedSpider which is the recommended spider to use
for scraping from an XML feed.
See documentation in docs/topics/spiders.rst
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any

View File

@ -1,7 +1,3 @@
"""
Scheduler queues
"""
from __future__ import annotations
import marshal

View File

@ -1,7 +1,3 @@
"""
Scrapy extension for collecting scraping stats
"""
from __future__ import annotations
import logging

View File

@ -1,5 +1,3 @@
"""Utils for built-in HTTP download handlers."""
from __future__ import annotations
from contextlib import contextmanager

View File

@ -1,5 +1,3 @@
"""Utilities related to asyncio and its support in Scrapy."""
from __future__ import annotations
import asyncio

View File

@ -1,5 +1,3 @@
"""Boto/botocore helpers"""
def is_botocore_available() -> bool:
try:

View File

@ -1,8 +1,3 @@
"""
This module contains data types used by Scrapy which are not included in the
Python Standard Library.
"""
from __future__ import annotations
import collections

View File

@ -1,7 +1,3 @@
"""
Helper functions for dealing with Twisted deferreds
"""
from __future__ import annotations
import asyncio

View File

@ -1,5 +1,3 @@
"""Some helpers for deprecation messages"""
from __future__ import annotations
import inspect

View File

@ -1,7 +1,3 @@
"""
pprint and pformat wrappers with colorization support
"""
import ctypes
import platform
import sys

View File

@ -1,5 +1,3 @@
"""Some debugging functions for working with the Scrapy engine"""
from __future__ import annotations
# used in global tests code

View File

@ -1,5 +1,3 @@
"""Helper functions for scrapy.http objects (Request, Response)"""
from __future__ import annotations
from typing import TYPE_CHECKING

View File

@ -1,5 +1,3 @@
"""Helper functions which don't fit anywhere else"""
from __future__ import annotations
import ast

View File

@ -1,7 +1,3 @@
"""
This module contains essential stuff that should've come with Python itself ;)
"""
from __future__ import annotations
import gc

View File

@ -1,8 +1,3 @@
"""
This module provides some useful functions for working with
scrapy.Request objects
"""
from __future__ import annotations
import hashlib

View File

@ -1,8 +1,3 @@
"""
This module provides some useful functions for working with
scrapy.http.Response objects
"""
from __future__ import annotations
import os

View File

@ -1,5 +1,3 @@
"""Helper functions for working with signals"""
from __future__ import annotations
import asyncio

View File

@ -1,9 +1,5 @@
"""
Module for processing Sitemaps.
Note: The main purpose of this module is to provide support for the
SitemapSpider, its API is subject to change without notice.
"""
# The main purpose of this module is to provide support for the SitemapSpider,
# its API is subject to change without notice.
from __future__ import annotations

View File

@ -1,5 +1,3 @@
"""Helper functions for working with templates"""
from __future__ import annotations
import re

View File

@ -1,7 +1,3 @@
"""
This module contains some assorted functions used in tests
"""
from __future__ import annotations
import asyncio

View File

@ -1,16 +1,7 @@
"""This module provides some functions and classes to record and report
references to live object instances.
If you want live objects for a particular class to be tracked, you only have to
subclass from object_ref (instead of object).
This library has a minimal performance impact.
.. note:: PyPy uses a tracing garbage collector, so objects may
remain in the ``live_refs`` longer than expected, even after they
go out of scope. If deterministic behavior is required, you may need
to explicitly trigger garbage collection or call ``trackref.live_refs.clear()``.
"""
# PyPy uses a tracing garbage collector, so objects may remain in live_refs
# longer than expected, even after they go out of scope. If deterministic
# behavior is required, you may need to explicitly trigger garbage collection
# or call trackref.live_refs.clear().
from __future__ import annotations

View File

@ -1,8 +1,3 @@
"""
This module contains general purpose URL functions not found in the standard
library.
"""
from __future__ import annotations
import re