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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- selector handling for `RETRY_CSS_SELECTORS` in `_handle_blocked_request` in `BeautifulSoupCrawler`
- selector handling in `enqueue_links` in `BeautifulSoupCrawler`

## [0.0.6](../../releases/tag/v0.0.6) - 2024-06-25
Expand Down
2 changes: 1 addition & 1 deletion src/crawlee/beautifulsoup_crawler/beautifulsoup_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def _handle_blocked_request(
raise SessionError(f'Assuming the session is blocked based on HTTP status code {status_code}')

matched_selectors = [
selector for selector in RETRY_CSS_SELECTORS if crawling_context.soup.find(selector) is not None
selector for selector in RETRY_CSS_SELECTORS if crawling_context.soup.select_one(selector) is not None
]

if matched_selectors:
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/beautifulsoup_crawler/test_beautifulsoup_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ async def server() -> AsyncGenerator[respx.MockRouter, None]:
</html>""",
)

mock.get('/fdyr', name='incapsula_endpoint').return_value = Response(
200,
text="""<html>
<head>
<title>Hello</title>
</head>
<body>
<iframe src=Test_Incapsula_Resource>
</iframe>
</body>
</html>""",
)

mock.get('/hjkl').return_value = generic_response
mock.get('/qwer').return_value = generic_response
mock.get('/uiop').return_value = generic_response
Expand Down Expand Up @@ -148,3 +161,10 @@ async def request_handler(context: BeautifulSoupCrawlingContext) -> None:
assert len(processed_urls) == 3
assert stats.requests_total == 3
assert stats.requests_finished == 3


async def test_handle_blocked_request(server: respx.MockRouter) -> None:
crawler = BeautifulSoupCrawler(request_provider=RequestList(['https://test.io/fdyr']), max_session_rotations=1)
stats = await crawler.run()
assert server['incapsula_endpoint'].called
assert stats.requests_failed == 1