Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/guides/architecture_overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class BasicCrawlingContext

class HttpCrawlingContext

class HttpCrawlingResult

class ParsedHttpCrawlingContext

class ParselCrawlingContext
Expand Down Expand Up @@ -152,8 +150,6 @@ class StagehandCrawlingContext

BasicCrawlingContext --|> HttpCrawlingContext

HttpCrawlingResult --|> HttpCrawlingContext

HttpCrawlingContext --|> ParsedHttpCrawlingContext

ParsedHttpCrawlingContext --|> ParselCrawlingContext
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading/upgrading_to_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ The crawler now reads a stall from the status, so it also sees a `ThrottlingRequ

### Responses are read lazily

`HttpClient.crawl` and `HttpClient.stream` are removed. `send_request` returns the response as soon as its headers arrive and reads the body only on `read` or `read_stream`. A response whose body you don't read keeps its connection until you call `aclose`. Use the response as an async context manager to close it:
`HttpClient.crawl` and `HttpClient.stream` are removed, and so is `HttpCrawlingResult`, which `crawl` returned. `HttpCrawlingContext` still has `http_response`. `http_response` now comes after the fields of `BasicCrawlingContext` instead of before them, so if you build a crawling context yourself, pass the fields by keyword. `send_request` returns the response as soon as its headers arrive and reads the body only on `read` or `read_stream`. A response whose body you don't read keeps its connection until you call `aclose`. Use the response as an async context manager to close it:

```python
# v1
Expand Down
3 changes: 1 addition & 2 deletions src/crawlee/crawlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ._abstract_http import AbstractHttpCrawler, AbstractHttpParser, HttpCrawlerOptions, ParsedHttpCrawlingContext
from ._basic import BasicCrawler, BasicCrawlerOptions, BasicCrawlingContext, ContextPipeline
from ._file_download import FileDownloadCrawler, FileDownloadCrawlingContext
from ._http import HttpCrawler, HttpCrawlingContext, HttpCrawlingResult
from ._http import HttpCrawler, HttpCrawlingContext

_install_import_hook(__name__)

Expand Down Expand Up @@ -129,7 +129,6 @@
'HttpCrawler',
'HttpCrawlerOptions',
'HttpCrawlingContext',
'HttpCrawlingResult',
'ParsedHttpCrawlingContext',
'ParselCrawler',
'ParselCrawlingContext',
Expand Down
11 changes: 8 additions & 3 deletions src/crawlee/crawlers/_abstract_http/_http_crawling_context.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
from __future__ import annotations

from dataclasses import dataclass, fields
from typing import Generic, Self, TypeVar
from typing import TYPE_CHECKING, Generic, Self, TypeVar

from crawlee._types import BasicCrawlingContext, EnqueueLinksFunction, ExtractLinksFunction, PageSnapshot
from crawlee._utils.docs import docs_group
from crawlee.http_clients import HttpCrawlingResult, HttpResponse

if TYPE_CHECKING:
from crawlee.http_clients import HttpResponse

TParseResult = TypeVar('TParseResult')
TSelectResult = TypeVar('TSelectResult')


@dataclass(frozen=True)
@docs_group('Crawling contexts')
class HttpCrawlingContext(BasicCrawlingContext, HttpCrawlingResult):
class HttpCrawlingContext(BasicCrawlingContext):
"""The crawling context used by the `AbstractHttpCrawler`."""

http_response: HttpResponse
Comment thread
Mantisus marked this conversation as resolved.
Resolved
"""The HTTP response received from the server."""

@classmethod
def from_basic_crawling_context(cls, context: BasicCrawlingContext, http_response: HttpResponse) -> Self:
"""Initialize a new instance from an existing `BasicCrawlingContext`."""
Expand Down
2 changes: 0 additions & 2 deletions src/crawlee/crawlers/_http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from crawlee.crawlers._abstract_http._http_crawling_context import HttpCrawlingContext
from crawlee.http_clients import HttpCrawlingResult

from ._http_crawler import HttpCrawler

__all__ = [
'HttpCrawler',
'HttpCrawlingContext',
'HttpCrawlingResult',
]
3 changes: 1 addition & 2 deletions src/crawlee/http_clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from crawlee._utils.try_import import try_import as _try_import

# These imports have only mandatory dependencies, so they are imported directly.
from ._base import HttpClient, HttpCrawlingResult, HttpResponse
from ._base import HttpClient, HttpResponse
from ._impit import ImpitHttpClient

_install_import_hook(__name__)
Expand All @@ -19,7 +19,6 @@
__all__ = [
'CurlImpersonateHttpClient',
'HttpClient',
'HttpCrawlingResult',
'HttpResponse',
'HttpxHttpClient',
'ImpitHttpClient',
Expand Down
14 changes: 0 additions & 14 deletions src/crawlee/http_clients/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import timedelta
from http import HTTPStatus
from time import monotonic
Expand Down Expand Up @@ -168,19 +167,6 @@ async def __aexit__(
await self.aclose()


@dataclass(frozen=True)
@docs_group('Crawling contexts')
class HttpCrawlingResult:
"""Result of an HTTP-only crawl.

Mainly for the purpose of composing specific crawling contexts (e.g. `BeautifulSoupCrawlingContext`,
`ParselCrawlingContext`, ...).
"""

http_response: HttpResponse
"""The HTTP response received from the server."""


@docs_group('HTTP clients')
class HttpClient(ABC):
"""An abstract base class for HTTP clients used in crawlers (`BasicCrawler` subclasses).
Expand Down
Loading