Formatting cookies.json into requests(cookies) Python - python

How can I use my cookie.json file in python request and log in website with this cookie cookies. This is my json file example:
[
{
"domain": "example.com",
"expirationDate": 161551211,
"hostOnly": false,
"httpOnly": false,
"name": "usernameexample",
"path": "/",
"sameSite": null,
"secure": false,
"session": false,
"storeId": null,
"value": "878203952"
},
{
"domain": "example.com",
"expirationDate": 164813154441,
"hostOnly": false,
"httpOnly": false,
"name": "usernameexample",
"path": "/",
"sameSite": "..x",
"secure": false,
"session": false,
"storeId": null,
"value": "is
},...]

Related

How to change your python twitter password if you have a username: password mail:password and full list of cookies?

I have a cookie for twitter and a list of data how can I change the password on my account?
login:pass:mail:pass:useragent:[{"domain": ".twitter.com", "expiry": 56456465, "httpOnly": false, "name": "_ga", "path": "/", "sameSite": "None", "secure": false, "value": "GA1.2.6454556419.1456564422"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "_gid", "path": "/", "sameSite": "None", "secure": true, "value": "GA1.2.16556094.167456562"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": true, "name": "_twitter_sess", "path": "/", "sameSite": "None", "secure": true, "value": "BAh7CSIKZmxhc2hJQertetyzythN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHyrtyrtyXRlZF9hdGwrCHC6ctmFAToMY3NyZl9ptyrtyrt80ebb7b207b24ed91371c3009"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": true, "name": "auth_token", "path": "/", "sameSite": "None", "secure": true, "value": "7b82294c72660b9bbrtyrtyrty846012c56"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "ct0", "path": "/", "sameSite": "Lax", "secure": true, "value": "adf9dac0673bd08cb53852ertyrtyrty7f88b830holikhthfghjb4913e99e8ad0c198jjjjjjjjjhr6a39442de97f9def99dc24e34b3c5044041b7b1aa6f31brtyrtyr4169d4c"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "gt", "path": "/", "sameSite": "None", "secure": true, "value": "1617136745568501761"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "guest_id", "path": "/", "sameSite": "None", "secure": true, "value": "v1%3A1thrrthr55806253"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "guest_id_ads", "path": "/", "sameSite": "None", "secure": true, "value": "v1%45334645yrth36"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "guest_id_marketing", "path": "/", "sameSite": "None", "secure": true, "value": "v1%3A167439041755806253"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": true, "name": "kdt", "path": "/", "sameSite": "None", "secure": true, "value": "hgh45y4hthrt65yhrtryrghfhgt"}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "personalization_id", "path": "/", "sameSite": "None", "secure": true, "value": "\"v1_f/BhbEr0L/45346hgrhg==\""}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "twid", "path": "/", "sameSite": "None", "secure": true, "value": "\"u=3453674574574646\""}, {"domain": ".twitter.com", "expiry": 1735929088, "httpOnly": false, "name": "lang", "path": "/", "sameSite": "None", "secure": true, "value": "en"}]
I searched for options in Google, but I didn't find anything I needed

Import Cookies in Selenium to login to Tiktok

I want to import my TikTok Cookies in Selenium, so I can login without E-mail etc. I have my TikTok Cookies in json format. I got them with the Cookie Editor Extension. They look like this: (They don't work anymore, you can't steal my account)
[
{
"name": "ak_bmsc",
"value": "8212602E930E6F64AA0624DD6E863C50~000000000000000000000000000000~YAAQDkhnaHKTwhaFAQAAEIRhpxJcYa0shIEWLBmNGIiqgWbNUircx0QW4jdNl7F89wAEX8WzhDq5jvRnPvdpQPfRnF+CP/ICnJFmCue4JUra0oFm7nzRiYPXTGeqwIcmlgv+7B727AcUG9qs47fWGeF86muhpkRb6f1/FE7OfM3QnmonaDERcIaylhWE8/hHewg1TpqVdfTuXNv+U0RxiKz0zoYh3k5FusVB8Gi0NxgwbldEEKgXQDL9/xtBduCowdUP0zL55IA1kFeiwT9z+BYFzFZ4fP8Dc7HCjdhpiHGzfBfBltgHKwJjZIlZSxNGZL3hDt3O79BdMQSRMxobCbhePnCJ7SECkdGzPl7gTOrK6H7W+AXsjVfMpxOXJjh6dKC+7elGpJgL97M=",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1673557663,
"storeId": null
},
{
"name": "tt-target-idc-sign",
"value": "5YxdfGLosvFdMgb1bXdwl1-FZzvdNya7FUu1ZT4HWrv3D_Cr3CMmxz92HBhdxocXBzBsdfOjE7ZCnwB8tEHmE7TO_Y7bRfD5X8a1FXR3CSgZrSu-Yh4m0g4VO3vxm9ZW4kUyNo8crey7ykJDvPerk_WXtmWHC2olcfK95CFMGSh2P12HmjK2bkCNwd8G67zIB9ruq8l3g6yP_wRwwe22TdU9seMC9Ej68Iv_aaOqvOLjjySEtKGgAITjeO7ILsZEeNcRRMzgs0zKlS5oHv0u34UY5BULmUq_u93KQsVhtD0MV918EjnXxyL0P0nzW3P14MD7o82iaHnhsYqgKGdQ2IuaUAt9-WRlZCEKjlz1qyGF7lMzJYAAcpdWeFvY8ngYrMweWs1FBUoUXdi2NC4abeH9-GA5hyDpufFG2gIpMJtduaN9_mbhqCsA5hzsUfKF5fHD5-PsTWGhk687sJA65pJODXhejGIh9pj7OO2kctvw0pMw7HIGp6rSq3W6t7Nd",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1705086503,
"storeId": null
},
{
"name": "_abck",
"value": "42D3C2D28425227E6C0BDE47B2356740~-1~YAAQBUhnaI4KwwWFAQAAhyhipwnW4qoS/PamAGRt5U3gP+fne8dib2iaTTsXfhJt27uYiaZHC8/Sj2nlhfx7w2rz9vVgfNYUpErbI+EvNCdrCitdoV1NDVaIQ4tjyP3ZOrsB9+CEtLbin+O9IfPHfxBdmU/9sbL73sM+4ht2uM55xsp4KSN7F/n6POqT7M+C73aPwmZJytQlzXLjIFLAGTFslRfr5yvMnwmlcxprokEMLUVCqunJ8qg2u9WPuoOkWzsD9qZn4CbwUQUz+PhXZl3/+niSB7ulOrDM3XQCR8YRivIr2JQT1V6uuxkKEfgGGKcDg0VJsITwY8/qzYYnbgM9cUl/7Ej29truMJiYDMUzNEPzMbcwYDl1nhMuIT2AIgoQEvmm7o/A7myM9F03vpbCrF+k/SyWAA==~0~-1~-1",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1705086507,
"storeId": null
},
{
"name": "csrf_session_id",
"value": "9d94d54a439c43831d2ebb24e4023dbf",
"domain": "www.tiktok.com",
"hostOnly": true,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": true,
"firstPartyDomain": "",
"partitionKey": null,
"storeId": null
},
{
"name": "msToken",
"value": "XD8GanFPqieP0PjK7ge-Odbup5gE6fYywLLdO8rQ_Uaz7_6QNkH36wNRlP898x8jixXc9lwofmuvzuZvimtWKg8UDIQw_XGDBzzzuIJj2uKx9NxnWIbMaWWrXl5qHPapTroL",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1674414517,
"storeId": null
},
{
"name": "sid_guard",
"value": "e5a873636ed0a691ad7b3ebe42b0b248%7C1673550501%7C5184000%7CMon%2C+13-Mar-2023+19%3A08%3A21+GMT",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1704654503,
"storeId": null
},
{
"name": "ttwid",
"value": "1%7CXYPMCdx97YCDwX5eXxScLqbcnCfWSV0NYr7S2XFUKYc%7C1673550510%7Cf31acce5c15c82d72348276034d4cc6ce6c9d43816c09f00e533b861d68081a0",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1705086511,
"storeId": null
},
{
"name": "store-country-code-src",
"value": "uid",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734502,
"storeId": null
},
{
"name": "cookie-consent",
"value": "{%22ga%22:false%2C%22af%22:false%2C%22fbp%22:false%2C%22lip%22:false%2C%22bing%22:false%2C%22ttads%22:false%2C%22reddit%22:false%2C%22criteo%22:false%2C%22version%22:%22v9%22}",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1704296770,
"storeId": null
},
{
"name": "uid_tt",
"value": "ce2fbdf69c460a3daae4993581f1c1071a7d96da8a90bb7065a49f608177b88c",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "passport_csrf_token_default",
"value": "521b10a4b8f43cbf5c6aea8119647675",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1674764431,
"storeId": null
},
{
"name": "msToken",
"value": "XD8GanFPqieP0PjK7ge-Odbup5gE6fYywLLdO8rQ_Uaz7_6QNkH36wNRlP898x8jixXc9lwofmuvzuZvimtWKg8UDIQw_XGDBzzzuIJj2uKx9NxnWIbMaWWrXl5qHPapTroL",
"domain": "www.tiktok.com",
"hostOnly": true,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1681326519,
"storeId": null
},
{
"name": "s_v_web_id",
"value": "verify_lcm0ddcs_0DcAH7sq_9nJU_43jE_A6QK_ghq0EToUMZdj",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": true,
"firstPartyDomain": "",
"partitionKey": null,
"storeId": null
},
{
"name": "store-idc",
"value": "maliva",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734502,
"storeId": null
},
{
"name": "ssid_ucp_v1",
"value": "1.0.0-KDk3ZjJhZTNkYzM0ZmNiNzg5YjAzZTdjNTM5NjZiYTU0N2U4NWRjZmEKHwiFiK2cnM-mtl8QpbWBngYYswsgDDCRtrL7BTgIQBIQAxoGbWFsaXZhIiBlNWE4NzM2MzZlZDBhNjkxYWQ3YjNlYmU0MmIwYjI0OA",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "tiktok_webapp_theme",
"value": "light",
"domain": ".www.tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1699470509,
"storeId": null
},
{
"name": "__tea_cache_tokens_1988",
"value": "{%22_type_%22:%22default%22%2C%22user_unique_id%22:%227170793161920546309%22%2C%22timestamp%22:1669580405594}",
"domain": ".www.tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1674155310,
"storeId": null
},
{
"name": "_tea_utm_cache_2643",
"value": "undefined",
"domain": ".www.tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1672415954,
"storeId": null
},
{
"name": "bm_mi",
"value": "2030D375CF747A8B159C50AD67CD9418~YAAQw882F3ylm/CEAQAAuWStjBIwllCZO1L7WjSeIVaJc2Kj3d9ca5OeYKd6V62x9l7atKASNLV4YMWI/A70aVb8/dIIeeAM6MmC2mvrGxIEgaSGNv9nRjZ6gAZUl8i2w/is6pvGX5q3ZMWPOXSLfXlT+lJFVMiFPsZQq3FL7fOBQ709q482di7y1S3bBrGJmKyK9Um7QoQ/Ko40g0R+Bk0lxkiUJXw11AWq3Gz6N5r5bFD7STibHp0i8gZTlPB+z0ndZVdfHfcvxF1S9UbJ5gagzlQO9RIYYdtNtkizEw3nzUgMLd74R7QVd9bcjXhAzKKQS9OcuQ==~1",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1673106957,
"storeId": null
},
{
"name": "bm_sv",
"value": "3F3B5DEE26756D70E68A9A13F04E6CC4~YAAQBUhnaJUKwwWFAQAA7V9ipxLydOaVu1dTtKoNtpWlMpoq5YYZXH+ViZ/K/KwtJnSviKaYv2Hh/LpJRg+/z4++gUhkoq3AF43/rsTBFWBQ7vzI/vnveu2cX5LwbMXAPY5/cdykiDMeFc6/wHh7w4AsuDESMwGHNExvgJW4ll97FXnZA4rczD4v7kKi2S7gt0L650Q8POBWcSNOQxJErU62gG+IycZ0OD7UMZEbI76HsAM6lESFqTzQNrT5k17q~1",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1673557711,
"storeId": null
},
{
"name": "bm_sz",
"value": "B3CD421535E3ECAC5684BCE9FD5843F8~YAAQDkhnaHSTwhaFAQAAEIRhpxIzFkyZFUC0BE1leEQqpUQUCJWy7G5PV8Dcp2PvPJ/QxwcrULqnA2qtT11JnzhWPQKyVbg2mdZxyD3vPD6Xzk3jj0x1QswYTt6en646vXEUeSHy+cjXgFulgMO27Zw/OJDqRpp3wbgVd0vFqW9YVzd4MIzd+EZsS6jFgMswfhGOrXns8uiVHdUYeNDH3sTEAeSQ/DTs0WdaP0Uw/vfNBxXbwcTlwVLR6nEV7h0PrNG9Mh/T5EaX+5w7SCXTpvxUfhpHM3t67w6aM3S/VoRBC+U=~3749186~3293746",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1673564863,
"storeId": null
},
{
"name": "cmpl_token",
"value": "AgQQAPOJF-RO0o9SdN5LuZ08-eJfUMmMP4cCYMoD6A",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "d_ticket",
"value": "104fb2bea810b5a081aa9711d93bf4e4dc3b6",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1705086501,
"storeId": null
},
{
"name": "odin_tt",
"value": "d202f5ea5cf2ba6774b02e1e1769dd372ba33f3c07c06c58bd1fd8f10eb381efdfb87e52db7b88f6340dca372e04bc34226db263ef5185bdad429b4bb6ee8fa318da837cba849c3f6eed37d113cc31cf",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1705086515,
"storeId": null
},
{
"name": "passport_auth_status",
"value": "4c9d9171576cd640966ba95641afe9da%2C748dfc5c46868df08354d280de4b48ee",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1676142503,
"storeId": null
},
{
"name": "passport_auth_status_ss",
"value": "4c9d9171576cd640966ba95641afe9da%2C748dfc5c46868df08354d280de4b48ee",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1676142503,
"storeId": null
},
{
"name": "passport_csrf_token",
"value": "521b10a4b8f43cbf5c6aea8119647675",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": false,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1674764431,
"storeId": null
},
{
"name": "passport_fe_beating_status",
"value": "true",
"domain": ".www.tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": false,
"sameSite": "no_restriction",
"session": true,
"firstPartyDomain": "",
"partitionKey": null,
"storeId": null
},
{
"name": "sessionid",
"value": "e5a873636ed0a691ad7b3ebe42b0b248",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "sessionid_ss",
"value": "e5a873636ed0a691ad7b3ebe42b0b248",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "sid_tt",
"value": "e5a873636ed0a691ad7b3ebe42b0b248",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "sid_ucp_v1",
"value": "1.0.0-KDk3ZjJhZTNkYzM0ZmNiNzg5YjAzZTdjNTM5NjZiYTU0N2U4NWRjZmEKHwiFiK2cnM-mtl8QpbWBngYYswsgDDCRtrL7BTgIQBIQAxoGbWFsaXZhIiBlNWE4NzM2MzZlZDBhNjkxYWQ3YjNlYmU0MmIwYjI0OA",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
},
{
"name": "store-country-code",
"value": "at",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734502,
"storeId": null
},
{
"name": "tt-target-idc",
"value": "useast1a",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": false,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734502,
"storeId": null
},
{
"name": "tt_chain_token",
"value": "bNh130YMkpdYrSobdL0/zQ==",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1673572106,
"storeId": null
},
{
"name": "tt_csrf_token",
"value": "1KPKsC8C-DV_gbCsZAXu5Vtc1G70rk0pa0BU",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "lax",
"session": true,
"firstPartyDomain": "",
"partitionKey": null,
"storeId": null
},
{
"name": "uid_tt_ss",
"value": "ce2fbdf69c460a3daae4993581f1c1071a7d96da8a90bb7065a49f608177b88c",
"domain": ".tiktok.com",
"hostOnly": false,
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "no_restriction",
"session": false,
"firstPartyDomain": "",
"partitionKey": null,
"expirationDate": 1678734503,
"storeId": null
}
]
I tried this code, but it just didn't work:
from selenium import webdriver
import json
print('get cookie')
driver=webdriver.Chrome()
driver.get("https://stackoverflow.com/")
cookies = driver.get_cookies()
with open('cookietest.json', 'w', newline='') as outputdata:
json.dump(cookies, outputdata)
print('send cookie')
import json
from selenium import webdriver
with open('cookietest.json', 'r', newline='') as inputdata:
cookies = json.load(inputdata)
curcookie = cookies[0]
driver=webdriver.Chrome()
driver.get("https://stackoverflow.com/")
driver.add_cookie(curcookie)
Can you help me?

How to extract only certain values from cookies in a json file?

Iam gathering cookies from a selenium browser and then writing them to a json file. I want to then read them and only extract the name and value keys and values. However, I dont know how to convert them back into a dictionary without changing the cookies in any way, which I see as a common answer on here.
Here are the cookies below
[{"domain": ".instagram.com", "httpOnly": true, "name": "rur", "path": "/", "secure": true, "value": "PRN"}, {"domain": ".instagram.com", "expiry": 1610372060, "httpOnly": true, "name": "shbid", "path": "/", "secure": true, "value": "2630"}, {"domain": ".instagram.com", "expiry": 1610372060, "httpOnly": true, "name": "shbts", "path": "/", "secure": true, "value": "1609767261.111102"}, {"domain": ".instagram.com", "expiry": 1641303259, "httpOnly": true, "name": "sessionid", "path": "/", "secure": true, "value": "5973912167%3A79EfmCoMj2hdDd%3A29"}, {"domain": ".instagram.com", "expiry": 1641216860, "httpOnly": false, "name": "csrftoken", "path": "/", "secure": true, "value": "z1i7aU8fUnFkO7jXS8eOcVzmzQVfCFTP"}, {"domain": ".instagram.com", "expiry": 1672839253, "httpOnly": false, "name": "mid", "path": "/", "secure": true, "value": "X_MZVgALAAFI1JXJOTF_ZG-E-Cny"}, {"domain": ".instagram.com", "expiry": 1617543260, "httpOnly": false, "name": "ds_user_id", "path": "/", "secure": true, "value": "5973912167"}, {"domain": ".instagram.com", "expiry": 1672839253, "httpOnly": true, "name": "ig_did", "path": "/", "secure": true, "value": "AD703D6F-E24A-4485-A1EC-9736E40C19C3"}, {"domain": ".instagram.com", "httpOnly": true, "name": "urlgen", "path": "/", "secure": true, "value": "\"{\\\"86.15.149.131\\\": 5089}:1kwQ05:r7Bsx0VcOwuIw_rejyFuGdmgAIo\""}, {"domain": "www.instagram.com", "expiry": 4765462453, "httpOnly": false, "name": "ig_cb", "path": "/", "secure": false, "value": "2"}]
I don't really know if this is exactly what you want but I extracted all the domain and value keys and value and put them back in a dictionary and put all the dictionary in a list
var = *YOUR COOKIES LIST*
liste = []
for i in range(len(var)) :
#print(var[i]["domain"])
#print(var[i]["value"])
dic = {"domain":var[i]["domain"],"value":var[i]["value"]}
liste.append(dic)
print(liste)
maybe this would have since you saved it as a file:
import json
with open('data.json', 'r') as f:
datas = json.load(f)
for data in datas:
print(data["name"], " : ", data["value"])
resulting in
rur : PRN
shbid : 2630
shbts : 1609767261.111102
sessionid : 5973912167%3A79EfmCoMj2hdDd%3A29
csrftoken : z1i7aU8fUnFkO7jXS8eOcVzmzQVfCFTP
mid : X_MZVgALAAFI1JXJOTF_ZG-E-Cny
ds_user_id : 5973912167
ig_did : AD703D6F-E24A-4485-A1EC-9736E40C19C3
urlgen : "{\"86.15.149.131\": 5089}:1kwQ05:r7Bsx0VcOwuIw_rejyFuGdmgAIo"
ig_cb : 2

how to save cookies from puppeteer and use the cookies to make request in python?

const puppeteer = require('puppeteer-extra')
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())
puppeteer.launch({ headless: true,ignoreHTTPSErrors:true, args: [ '--no-sandbox', '--proxy-server=51.158.111.242:8811' ] }).then(async browser => {
console.log('Running tests..')
const page = await browser.newPage()
await page.goto('https://google.com/')
const cookies = await page.cookies();
console.log(cookies);
await fs.writeFile('./cookies.json', JSON.stringify(cookies, null, 2));
await page.screenshot({ path: 'testresult.png', fullPage: true })
await browser.close()
})
after saving the cookies into the file, it saves multiple cookies dictionary in file
[
{
"name": "_gat",
"value": "1",
"domain": "www.google.com",
"path": "/",
"expires": 1582024891,
"size": 5,
"httpOnly": false,
"secure": false,
"session": false
},
{
"name": "_gid",
"value": "GA1.2.1936512649.1582024831",
"domain": "www.google.com",
"path": "/",
"expires": 1582111231,
"size": 31,
"httpOnly": false,
"secure": false,
"session": false
},
{
"name": "_ga",
"value": "GA1.2.1830413277.1582024831",
"domain": "www.google.com",
"path": "/",
"expires": 1645096831,
"size": 30,
"httpOnly": false,
"secure": false,
"session": false
},
{
"name": "__cfduid",
"value": "d9ccc472957afbae818db60dff47cc5e01582024830",
"domain": "www.google.com",
"path": "/",
"expires": 1584616830.613503,
"size": 51,
"httpOnly": true,
"secure": true,
"session": false,
"sameSite": "Lax"
}
]
I am not able to decide which one should use for making a request in the python-requests module?

How can you extract data from this json using, beautifulsoup and python?

how can get those two values utc_last_updated and name given the following json ?
I used requests, to get to fetch the content, and then I used BeautifulSoup to make it like it is now. But now I just want to extract the two values that I have shown.
"data": [
{
"scm": "hg",
"has_wiki": false,
"last_updated": "2016-03-23T14:05:27.433",
"no_forks": false,
"created_on": "2016-03-18T22:55:52.705",
"owner": "user",
"email_mailinglist": "",
"is_mq": false,
"size": 420034,
"read_only": false,
"fork_of": null,
"mq_of": null,
"state": "available",
"utc_created_on": "2016-03-18 21:55:52+00:00",
"website": "",
"description": "",
"has_issues": false,
"is_fork": false,
"slug": "store",
"is_private": true,
"name": "store",
"language": "python",
"utc_last_updated": "2016-03-23 13:05:27+00:00",
"no_public_forks": true,
"creator": null,
"resource_uri": "/1.0/repositories/my_url"
},
{
"scm": "hg",
"has_wiki": false,
"last_updated": "2016-03-18T12:26:22.261",
"no_forks": false,
"created_on": "2016-03-18T12:19:08.262",
"owner": "user",
"email_mailinglist": "",
"is_mq": false,
"size": 173137,
"read_only": false,
"fork_of": null,
"mq_of": null,
"state": "available",
"utc_created_on": "2016-03-18 11:19:08+00:00",
"website": "",
"description": "",
"has_issues": false,
"is_fork": false,
"name": 'foo'
"is_private": true,,
"language": "python",
"utc_last_updated": "2016-03-18 11:26:22+00:00",
"no_public_forks": true,
"creator": null,
"resource_uri": "/1.0/repositories/my_rl"
},
}
I will appreciate any help.
You've got a JSON response, not HTML - parse it with json module:
import json
data = json.loads(response)
for item in data["data"]:
print(item["utc_last_updated"])

Categories

Resources