"""Search engine result parsing — Bing, DuckDuckGo, Yahoo, and site crawling. Extracted from search.py to keep the cmdlet class focused on orchestration. """ from __future__ import annotations from typing import Any, Dict, List, Optional, Sequence from collections import deque from pathlib import Path import re import time import html as _html from urllib.parse import urlparse, parse_qs, unquote, urljoin from SYS.logger import debug from SYS.payload_builders import normalize_file_extension _WHITESPACE_RE = re.compile(r"\s+") _SITE_TOKEN_RE = re.compile(r"(?:^|\s)site:([^\s,]+)", flags=re.IGNORECASE) _FILETYPE_TOKEN_RE = re.compile( r"(?:^|\s)(?:ext|filetype|type):\.?([a-z0-9]{1,12})\b", flags=re.IGNORECASE, ) _SITE_REMOVE_RE = re.compile(r"(?:^|\s)site:[^\s,]+", flags=re.IGNORECASE) _FILETYPE_REMOVE_RE = re.compile( r"(?:^|\s)(?:ext|filetype|type):\.?[a-z0-9]{1,12}\b", flags=re.IGNORECASE, ) _SCHEME_PREFIX_RE = re.compile(r"^[a-z]+:") _YAHOO_RU_RE = re.compile(r"/RU=([^/]+)/RK=", flags=re.IGNORECASE) _HTML_TAG_RE = re.compile(r"<[^>]+>") _DDG_RESULT_ANCHOR_RE = re.compile( r']+class="[^"]*result__a[^"]*"[^>]+href="([^"]+)"[^>]*>(.*?)', flags=re.IGNORECASE | re.DOTALL, ) _GENERIC_ANCHOR_RE = re.compile( r']+href=["\']([^"\']+)["\'][^>]*>(.*?)', flags=re.IGNORECASE | re.DOTALL, ) _BING_RESULT_ANCHOR_RE = re.compile( r'