Adding a function to intercept and drop unwanted requests

This commit is contained in:
Karim shoair
2024-11-03 16:25:55 +02:00
parent 0867d9e78a
commit c8c494e73f
2 changed files with 12 additions and 0 deletions
+1
View File
@@ -14,5 +14,6 @@ from .custom import (
)
from .navigation import (
js_bypass_path,
intercept_route,
construct_websocket_url,
)
+11
View File
@@ -3,7 +3,18 @@ Functions related to files and URLs
"""
import os
import logging
from urllib.parse import urlparse, urlencode
from playwright.sync_api import Route
from scrapling.engines.constants import DEFAULT_DISABLED_RESOURCES
def intercept_route(route: Route):
if route.request.resource_type in DEFAULT_DISABLED_RESOURCES:
logging.debug(f'Blocking background resource "{route.request.url}" of type "{route.request.resource_type}"')
return route.abort()
return route.continue_()
def construct_websocket_url(base_url, query_params):