GithubHelp home page GithubHelp logo

how to get cookies ? about rod HOT 4 CLOSED

go-rod avatar go-rod commented on July 18, 2024
how to get cookies ?

from rod.

Comments (4)

ysmood avatar ysmood commented on July 18, 2024 3

Released v0.27.3, now you have Cookies to get the cookies directly:

https://github.com/ysmood/rod/blob/52fc1e08901b8ad7a11856c6bb888c67bc870b76/page_test.go#L33

from rod.

ysmood avatar ysmood commented on July 18, 2024 1

The best way to learn how to use a golang lib is to read its unit tests.

Here's the unit test for getting cookie: https://github.com/ysmood/rod/blob/460f5418e3eae7ac328ce32ec2b78182dc791683/page_test.go#L33

Check the titles of unit tests, you will find more examples that might be useful 😉

from rod.

widnyana avatar widnyana commented on July 18, 2024 1

@ysmood thank you for the suggestion :)

I already try that actually, and got error like this:

panic: [rod] DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document.
    at <anonymous>:1:32
{"result":{"type":"object","subtype":"error","className":"DOMException","description":"DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document.\n    at <anonymous>:1:32","objectId":"{\"injectedScriptId\":1,\"id\":3}","preview":{"type":"object","subtype":"error","description":"DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document.\n    at <anonymous>:1:32","overflow":false,"properties":[{"name":"stack","type":"accessor"},{"name":"code","type":"number","value":"18"},{"name":"name","type":"string","value":"SecurityError"},{"name":"message","type":"string","value":"Failed to read the 'cookie' property from 'Document': Access is denied for this document."}]}},"exceptionDetails":{"exceptionId":1,"text":"Uncaught","lineNumber":0,"columnNumber":31,"scriptId":"22","exception":{"type":"object","subtype":"error","className":"DOMException","description":"DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document.\n    at <anonymous>:1:32","objectId":"{\"injectedScriptId\":1,\"id\":4}","preview":{"type":"object","subtype":"error","description":"DOMException: Failed to read the 'cookie' property from 'Document': Access is denied for this document.\n    at <anonymous>:1:32","overflow":false,"properties":[{"name":"stack","type":"accessor"},{"name":"code","type":"number","value":"18"},{"name":"name","type":"string","value":"SecurityError"},{"name":"message","type":"string","value":"Failed to read the 'cookie' property from 'Document': Access is denied for this document."}]}}}}

goroutine 1 [running]:
github.com/ysmood/kit/pkg/utils.E(0xc0001d2af0, 0x1, 0x1, 0x0, 0xe24b75, 0xf)
        /home/widnyana/.gvm/pkgsets/go1.13.5/global/pkg/mod/github.com/ysmood/[email protected]/pkg/utils/utils.go:33 +0xab
github.com/ysmood/rod.(*Page).Eval(0xc000172000, 0xe24b75, 0xf, 0x0, 0x0, 0x0, 0x1)
        /home/widnyana/.gvm/pkgsets/go1.13.5/global/pkg/mod/github.com/ysmood/[email protected]/sugar.go:232 +0xf8


long story short, I can make my snippet above works by adding code below before calling RodGetCookies

el := page.WaitLoad().Element("#topsection > div > h1")
elStable := meh.WaitStable().WaitVisible()  // <-- this one
fmt.Println(elStable.Text())

closing this issue, and again thank you for creating this library, cheers! 🍻

from rod.

widnyana avatar widnyana commented on July 18, 2024

thank you @ysmood !

from rod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.