Merge pull request #1529 from unclecode/fix/remove_overlay_elements
Fix remove_overlay_elements functionality by calling injected JS function.
This commit is contained in:
@@ -1383,9 +1383,10 @@ class AsyncPlaywrightCrawlerStrategy(AsyncCrawlerStrategy):
|
|||||||
try:
|
try:
|
||||||
await self.adapter.evaluate(page,
|
await self.adapter.evaluate(page,
|
||||||
f"""
|
f"""
|
||||||
(() => {{
|
(async () => {{
|
||||||
try {{
|
try {{
|
||||||
{remove_overlays_js}
|
const removeOverlays = {remove_overlays_js};
|
||||||
|
await removeOverlays();
|
||||||
return {{ success: true }};
|
return {{ success: true }};
|
||||||
}} catch (error) {{
|
}} catch (error) {{
|
||||||
return {{
|
return {{
|
||||||
|
|||||||
@@ -364,5 +364,19 @@ async def test_network_error_handling():
|
|||||||
async with AsyncPlaywrightCrawlerStrategy() as strategy:
|
async with AsyncPlaywrightCrawlerStrategy() as strategy:
|
||||||
await strategy.crawl("https://invalid.example.com", config)
|
await strategy.crawl("https://invalid.example.com", config)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_remove_overlay_elements(crawler_strategy):
|
||||||
|
config = CrawlerRunConfig(
|
||||||
|
remove_overlay_elements=True,
|
||||||
|
delay_before_return_html=5,
|
||||||
|
)
|
||||||
|
|
||||||
|
response = await crawler_strategy.crawl(
|
||||||
|
"https://www2.hm.com/en_us/index.html",
|
||||||
|
config
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "Accept all cookies" not in response.html
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pytest.main([__file__, "-v"])
|
pytest.main([__file__, "-v"])
|
||||||
Reference in New Issue
Block a user