How to send a cookie to the webbrowser using Python (I am using version 3.7)?
I know how to open a website:
import webbrowser
webbrowser.open("http://www.example.com", new=2)
But I have no idea, how to open that site with some cookies saved somewhere.
I solved the problem using selenium and a webdriver.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.example.com")
browser.add_cookie({
'name' : 'myLovelyCookie',
'value' : 'myLovelyValue'
})
And the result: Cookie
Not sure how to do it using the webbrowser library, but this can be easily done with the requests library. For example:
import requests
cookie = {
'uid': 'example_user_id',
}
url = "https://example.com"
req = requests.get(url, cookies=cookie)
From there you can read the content of the server’s response, contained in req.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With