def default_interceptor(request: selenium_request.Request): """ Inner function that acts like a proxy, it removes any requests we don't want. @param request: The current request @type request: selenium_request.Request @return: None """ # Block PNG, JPEG and GIF images. if request.path.endswith(('.png', '.jpg', '.gif')): request.abort() # Abort the unwanted request.
def interceptor(request: Request) -> None: if request.path.endswith((".png", ".jpg", ".gif")): request.abort() return if ( "edmunds.com" not in request.host and "edmunds-media.com" not in request.host ): request.abort() return if "activate" in request.path or "certified-program" in request.path: request.abort() return request.headers["User-Agent"] = ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/99.0.4844.82 Safari/537.36 Vivaldi/4.3" ) if (ffkey := "fetchSuggestedFacets") in request.params.keys(): new_params = request.params new_params[ffkey] = "false" request.params = new_params
def _intercept_requests(self, request: Request): # Intercept Network Requests - E.g. Block Ads/Malware if self.should_block_request(url=request.url): request.abort()