From 75d46cbdc6ba76ef927c794145cd5804e21b74c5 Mon Sep 17 00:00:00 2001 From: Marius Mutu Date: Fri, 15 May 2026 13:49:58 +0300 Subject: [PATCH] headless --- btgo_scraper.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/btgo_scraper.py b/btgo_scraper.py index e7770dd..fcb8c3e 100644 --- a/btgo_scraper.py +++ b/btgo_scraper.py @@ -390,13 +390,31 @@ class BTGoScraper: # display): viewport-ul setat pe context (CSS) nu se propaga la # fereastra fizica, iar BT afiseaza un splash "redirect to store" # sub ~1100px care ascunde input#user. + launch_args = ['--window-size=1920,1080'] + context_kwargs = {'viewport': {'width': 1920, 'height': 1080}} + + if self.config.HEADLESS: + # Playwright 1.48: headless=True foloseste VECHIUL mod headless, + # blocat de WAF-ul Akamai al BT. Fortam NOUL mod headless + # (--headless=new) cu headless=False ca Playwright sa nu adauge + # --headless=old. Randeaza ca un Chrome real, fara fereastra -> + # CPU mult mai mic decat headed software-rendering in session 0. + launch_args.append('--headless=new') + # UA-ul noului mod headless contine 'HeadlessChrome' - semnatura + # pe care o detecteaza Akamai. Il inlocuim cu UA de Chrome normal. + context_kwargs['user_agent'] = ( + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/130.0.0.0 Safari/537.36' + ) + browser = p.chromium.launch( - headless=self.config.HEADLESS, - slow_mo=100 if not self.config.HEADLESS else 0, - args=['--window-size=1920,1080'] + headless=False, + slow_mo=0 if self.config.HEADLESS else 100, + args=launch_args, ) - context = browser.new_context(viewport={'width': 1920, 'height': 1080}) + context = browser.new_context(**context_kwargs) # Blocheaza trackere care fac polling continuu pe homepage BT si # pun renderer-ul la 80-100% CPU pe hardware slab. Nu sunt folosite