{"record":{"id":"19df09a2a9ccd536","repo":"NanmiCoder/MediaCrawler","slug":"playwright-page-is-required-for-browser-based-sear","errorCode":null,"errorMessage":"playwright_page is required for browser-based search","messagePattern":"playwright_page is required for browser-based search","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"media_platform/tieba/client.py","lineNumber":396,"sourceCode":"        page: int = 1,\n        page_size: int = 10,\n        sort: SearchSortType = SearchSortType.TIME_DESC,\n        note_type: SearchNoteType = SearchNoteType.FIXED_THREAD,\n    ) -> List[TiebaNote]:\n        \"\"\"\n        Search Tieba posts by keyword (uses Playwright to access page, avoiding API detection)\n        Args:\n            keyword: Keyword\n            page: Page number\n            page_size: Page size\n            sort: Result sort method\n            note_type: Post type (main thread | main thread + reply mixed mode)\n        Returns:\n\n        \"\"\"\n        if not self.playwright_page:\n            utils.logger.error(\"[BaiduTieBaClient.get_notes_by_keyword] playwright_page is None, cannot use browser mode\")\n            raise Exception(\"playwright_page is required for browser-based search\")\n\n        params = {\n            \"rn\": max(page_size, 20),\n            \"st\": sort.value,\n            \"word\": keyword,\n            \"needbrand\": 1,\n            \"sug_type\": 2,\n            \"pn\": page,\n            \"come_from\": \"search\",\n            \"subapp_type\": \"pc\",\n            \"_client_type\": \"20\",\n        }\n        utils.logger.info(\n            f\"[BaiduTieBaClient.get_notes_by_keyword] Accessing search API: \"\n            f\"{self._host}/mo/q/search/multsearch?{urlencode(params)}\"\n        )\n\n        try:","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/tieba/client.py#L378-L414","documentation":"Raised by BaiduTieBaClient.get_notes_by_keyword (media_platform/tieba/client.py:396) when self.playwright_page is None. Tieba search is implemented exclusively through a live Playwright page context (to bypass API signature detection), so without a browser page the method cannot run and refuses with an explicit guard rather than an AttributeError.","triggerScenarios":"Instantiating BaiduTieBaClient without a browser context and calling get_notes_by_keyword; or calling it before the crawler attaches the Playwright page (page not yet created/logged in); or after the browser was closed and the reference cleared.","commonSituations":"Using the client in a headless script/tests without starting Playwright; a code path that constructs the client for pure HTTP API calls and then reuses it for search; race where search starts before login finishes creating the page.","solutions":["Launch a Playwright browser, create a context/page, and pass/set playwright_page on the client before searching","Ensure the crawler's login flow (which creates the page) has completed before keyword search begins","If you only need API-based data, use the API-backed methods (e.g. get_notes_by_tieba_name still requires a page — use the HTTP-frs endpoints) or a different platform client"],"exampleFix":"# before\nclient = BaiduTieBaClient()\nnotes = await client.get_notes_by_keyword('python')\n\n# after\nbrowser = await playwright.chromium.launch(headless=False)\ncontext = await browser.new_context()\npage = await context.new_page()\nclient = BaiduTieBaClient(playwright_page=page)\nnotes = await client.get_notes_by_keyword('python')","handlingStrategy":"type-guard","validationCode":"if not getattr(client, \"playwright_page\", None):\n    raise RuntimeError(\"Start browser and attach playwright_page before keyword search\")","typeGuard":"def has_browser_page(client) -> bool:\n    page = getattr(client, \"playwright_page\", None)\n    return page is not None and not page.is_closed()","tryCatchPattern":null,"preventionTips":["Always run the platform login/browser bootstrap before search calls","Check page.is_closed() before reusing a client after long pauses","Install Playwright browsers in the deploy environment (playwright install)"],"tags":["playwright","tieba","browser-context","validation"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}