Python
Customization
Configure transport, selectors, parsers, and error handling.
Proxy configuration
Route requests through SOCKS5 proxies for privacy or to bypass restrictions.
Python
client = TeleGlanceClient(proxy="socks5://127.0.0.1:9050")
# With authentication
client = TeleGlanceClient(proxy="socks5://user:pass@proxy.example.com:1080")Requires the socks extra: pip install "teleglance[socks]"
Rate limiting
Control request rate to avoid triggering Telegram's rate limits.
Python
# Default: 1 request per second
client = TeleGlanceClient(rate_limit=1.0)
# More conservative
client = TeleGlanceClient(rate_limit=2.0)
# Aggressive (risk rate limiting)
client = TeleGlanceClient(rate_limit=0.5)Custom headers
Override User-Agent or add custom headers.
Python
client = TeleGlanceClient(headers={
"User-Agent": "MyBot/1.0",
"Accept-Language": "en-US,en;q=0.9",
})Strict parsing
Enable strict mode to raise exceptions on parsing warnings.
Python
# Default: log warnings but continue
client = TeleGlanceClient(strict_parsing=False)
# Strict: raise ParseError on any parsing issue
client = TeleGlanceClient(strict_parsing=True)Custom selectors
Override CSS selectors if Telegram changes their markup.
Python
from teleglance.parsing.selectors import Selectors
custom_selectors = Selectors(
channel_title=".tgme_channel_info_header_title",
message_bubble=".tgme_widget_message",
# ... other selectors
)
client = TeleGlanceClient(selectors=custom_selectors)Request hooks
Inspect or modify requests before they're sent.
Python
def log_request(url, params):
print(f"GET {url} {params}")
client = TeleGlanceClient(request_hooks=[log_request])Response hooks
Inspect responses after they arrive.
Python
def log_response(response):
print(f"Response: {response.status_code} {len(response.content)} bytes")
client = TeleGlanceClient(response_hooks=[log_response])