Files
proxy-scraper-checker/proxy_scraper_checker/http.py
T
monosansandGitHub e4047e16ae Huge update
- Drop support for Python 3.7.
- Use offline geolocation database instead of ip-api.com.
- Add support for proxy authentication.
- Add pre-compiled binaries.
- Refactor the code by a lot.
- Simplify config.
- Add automatic text encoding detection.
- Use TOML instead of INI for configuration.
- Add support for using httpbin-compatible services and services which return plain IP address for getting proxy's exit node.
- Add support for reading proxy lists from local files.
- Add support for saving to json.
- Remove support for saving geolocation to txt, use json instead.
- Improve parser.
- Improve config validation.
- Use poetry instead of requirements.txt.
- Use venv in start scripts.
2024-01-21 17:45:01 +00:00

26 lines
675 B
Python

from __future__ import annotations
import ssl
from functools import lru_cache
from types import MappingProxyType
import certifi
import charset_normalizer
from aiohttp import ClientResponse, DummyCookieJar, hdrs
SSL_CONTEXT = ssl.create_default_context(cafile=certifi.where())
HEADERS: MappingProxyType[str, str] = MappingProxyType({
hdrs.USER_AGENT: (
"Mozilla/5.0 (Windows NT 10.0; rv:121.0) Gecko/20100101 Firefox/121.0"
)
})
@lru_cache(None)
def get_cookie_jar() -> DummyCookieJar:
return DummyCookieJar()
def fallback_charset_resolver(r: ClientResponse, b: bytes) -> str: # noqa: ARG001
return charset_normalizer.from_bytes(b)[0].encoding