Skip to content

Page cookies in the callback #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Ehsan-U opened this issue Feb 15, 2025 · 0 comments
Open

Page cookies in the callback #339

Ehsan-U opened this issue Feb 15, 2025 · 0 comments

Comments

@Ehsan-U
Copy link

Ehsan-U commented Feb 15, 2025

Is it possible to access the playwright cookies in the callback without passing the page itself ? it can be accessed by storing into global variable but that could cause issues in case of multiple pages.
It would be very useful to have the page cookies in the callback.

    def start_requests(self) -> Iterable[Request]:
        url = "https://corp.sec.state.ma.us/CorpWeb/CorpSearch/CorpSearch.aspx"
        yield scrapy.Request(url, callback=self.parse, meta={
            "playwright": True,
            "playwright_page_methods": [
                PageMethod(self.init_session)
            ]
        })

    async def init_session(self, page: Page) -> None:
        cookies = await page.context.cookies()
        return cookies
    
    def parse(self, response: Response):
        # how to access playwright cookies here, 
        pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant