Merge pull request 'fix(msk-collector): узкий ретрай page.content() на гонке перенавигации' (#3424) from fix/msk-collector-nav-race into main
All checks were successful
Deploy Trade-In / build-backend (push) Has been skipped
Deploy Trade-In / deploy (push) Successful in 54s
Deploy Trade-In / changes (push) Successful in 11s
Deploy Trade-In / test (push) Has been skipped
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / build-browser (push) Has been skipped
Deploy Trade-In / deploy-status (push) Successful in 1s
Deploy Trade-In / perimeter-smoke (push) Successful in 11s
All checks were successful
Deploy Trade-In / build-backend (push) Has been skipped
Deploy Trade-In / deploy (push) Successful in 54s
Deploy Trade-In / changes (push) Successful in 11s
Deploy Trade-In / test (push) Has been skipped
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / build-browser (push) Has been skipped
Deploy Trade-In / deploy-status (push) Successful in 1s
Deploy Trade-In / perimeter-smoke (push) Successful in 11s
This commit is contained in:
commit
1e96a6f12d
2 changed files with 24 additions and 1 deletions
1
tradein-mvp/scripts/local-avito-msk/.gitignore
vendored
Normal file
1
tradein-mvp/scripts/local-avito-msk/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
runs/
|
||||
|
|
@ -270,10 +270,32 @@ class Loader:
|
|||
await self._page.wait_for_selector('[data-marker="item"]', timeout=7_000)
|
||||
except Exception: # noqa: BLE001 — пустая/блочная страница разбирается ниже
|
||||
pass
|
||||
html = await self._page.content()
|
||||
html = await self._read_content()
|
||||
_guard(html, status)
|
||||
return html, status
|
||||
|
||||
async def _read_content(self, attempts: int = 4) -> str:
|
||||
"""page.content() с узким ретраем на гонку клиентской перенавигации.
|
||||
|
||||
Авито дорисовывает выдачу после domcontentloaded, и content() иногда
|
||||
попадает ровно в момент смены документа: "Unable to retrieve content
|
||||
because the page is navigating and changing the content". Это НЕ отказ
|
||||
площадки — гвардов не касается, поэтому ретраим только эту ошибку и
|
||||
только её, а любую другую поднимаем как есть.
|
||||
"""
|
||||
last: Exception | None = None
|
||||
for i in range(attempts):
|
||||
try:
|
||||
return await self._page.content()
|
||||
except Exception as exc: # noqa: BLE001 — сузили проверкой текста ниже
|
||||
if "page is navigating" not in str(exc):
|
||||
raise
|
||||
last = exc
|
||||
print(f" content() поймал перенавигацию, попытка {i + 2}/{attempts}",
|
||||
flush=True)
|
||||
await asyncio.sleep(1.5)
|
||||
raise RuntimeError(f"page.content() не отдал документ за {attempts} попыток") from last
|
||||
|
||||
|
||||
# --- заливка в msk_raw -----------------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue