added ability to set default user agent #2
@@ -11,13 +11,14 @@ import random
|
|||||||
from aioproxies import AioProxies
|
from aioproxies import AioProxies
|
||||||
from aioweb import Response
|
from aioweb import Response
|
||||||
from aioweb_tls import CurlCffi, TLSSession
|
from aioweb_tls import CurlCffi, TLSSession
|
||||||
|
from fake_useragent import UserAgent
|
||||||
|
|
||||||
from monitor_utils.constants import CLIENT_IDENTIFIERS, RETRY_LIMIT
|
from monitor_utils.constants import CLIENT_IDENTIFIERS, RETRY_LIMIT
|
||||||
|
|
||||||
|
UA = UserAgent()
|
||||||
|
|
||||||
def get_default_session(
|
|
||||||
proxies: AioProxies, headers: dict | None = None
|
def get_default_session(proxies: AioProxies, headers: dict | None = None) -> TLSSession:
|
||||||
) -> TLSSession:
|
|
||||||
"""Return a TLSSession impersonating a random client fingerprint.
|
"""Return a TLSSession impersonating a random client fingerprint.
|
||||||
|
|
||||||
Fingerprint rotation lives here so every monitor rotates the same way; the
|
Fingerprint rotation lives here so every monitor rotates the same way; the
|
||||||
@@ -41,6 +42,8 @@ def get_default_session(
|
|||||||
the proxy pool attached as proxy_pool.
|
the proxy pool attached as proxy_pool.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
headers = headers or {}
|
||||||
|
headers.setdefault("User-Agent", UA.chrome)
|
||||||
impersonate = random.choice(CLIENT_IDENTIFIERS)
|
impersonate = random.choice(CLIENT_IDENTIFIERS)
|
||||||
session = TLSSession(backend=CurlCffi(impersonate=impersonate), headers=headers)
|
session = TLSSession(backend=CurlCffi(impersonate=impersonate), headers=headers)
|
||||||
session.proxy_pool = proxies
|
session.proxy_pool = proxies
|
||||||
|
|||||||
Reference in new issue
Block a user