Skip to content

18 extends

Zuko edited this page Jan 21, 2026 · 1 revision

Extends - Extensions

Extended functionality và specialized implementations

CurlSslAntiDetectSession

Anti-detection HTTP session using curl_cffi:

from core.extends import CurlSslAntiDetectSession

session = CurlSslAntiDetectSession(
    impersonate='chrome110',
    timeout=30
)

# GET request
response = session.get('https://api.example.com')
print(response.text)

# POST request
response = session.post(
    'https://api.example.com/data',
    json={'key': 'value'}
)

# With headers
response = session.get(
    'https://api.example.com',
    headers={'User-Agent': 'Custom'}
)

Features

  • Browser impersonation (Chrome, Firefox, Safari)
  • TLS fingerprint randomization
  • Anti-bot detection
  • Session persistence

Usage Examples

Basic Request

from core.extends import CurlSslAntiDetectSession

session = CurlSslAntiDetectSession()

# Simple GET
response = session.get('https://example.com')
print(response.status_code)
print(response.text)

With Impersonation

# Impersonate Chrome 110
session = CurlSslAntiDetectSession(impersonate='chrome110')

# Impersonate Firefox
session = CurlSslAntiDetectSession(impersonate='firefox')

# Impersonate Safari
session = CurlSslAntiDetectSession(impersonate='safari')

In Background Task

from core.taskSystem import AbstractTask
from core.extends import CurlSslAntiDetectSession

class ScrapingTask(AbstractTask):
    def handle(self):
        session = CurlSslAntiDetectSession(impersonate='chrome110')
        
        try:
            response = session.get('https://example.com')
            data = response.json()
            
            # Process data...
            
        except Exception as e:
            self.fail(f'Request failed: {e}')
    
    def _performCancellationCleanup(self):
        pass

Best Practices

✅ DO

# Use in background tasks
class MyTask(AbstractTask):
    def handle(self):
        session = CurlSslAntiDetectSession()
        response = session.get(url)

# Set appropriate timeout
session = CurlSslAntiDetectSession(timeout=30)

# Handle exceptions
try:
    response = session.get(url)
except Exception as e:
    logger.error(f'Request failed: {e}')

❌ DON'T

# Don't use in UI thread
class MyHandler(BaseCtlHandler):
    def onButtonClicked(self):
        session = CurlSslAntiDetectSession()  # Wrong! Use in task

# Don't forget timeout
session = CurlSslAntiDetectSession()  # No timeout!

Related Documentation

Clone this wiki locally