Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/crawlee/crawlers/_beautifulsoup/_beautifulsoup_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING, Literal

from bs4 import BeautifulSoup, Tag
Expand All @@ -23,11 +24,12 @@ def __init__(self, parser: BeautifulSoupParserType = 'lxml') -> None:

@override
async def parse(self, response: HttpResponse) -> BeautifulSoup:
return BeautifulSoup(await response.read(), features=self._parser)
body = await response.read()
return await asyncio.to_thread(BeautifulSoup, body, features=self._parser)

@override
async def parse_text(self, text: str) -> BeautifulSoup:
return BeautifulSoup(text, features=self._parser)
return await asyncio.to_thread(BeautifulSoup, text, features=self._parser)

@override
def is_matching_selector(self, parsed_content: Tag, selector: str) -> bool:
Expand Down
Loading