I want to use cookie from EditThisCookie in order to get available items from account, so I saved them in a 'cookie.json' file, but when I'm trying to use them and send a get request, its just not logging in
Sample of 'cookies.json':
[
{
"domain": ".github.com",
"expirationDate": 12401290312391203012,
"hostOnly": false,
"httpOnly": false,
"name": "_octo",
"path": "/",
"sameSite": "lax",
"secure": true,
"session": false,
"storeId": "0",
"value": "MIGHT_BE_SMTH_PERSONAL :(",
"id": 1
}
]
btw, expirationDate
and value
values are hidden, cuz I don't know what people can do with it
Code:
import requests
import json
url = 'https://steamcommunity.com/inventory/steamid/730/2?&count=5000'
with open('cookies.json', 'r') as f:
json_data = f.read()
parsed_data = json.loads(json_data)
if isinstance(parsed_data, list) and all(isinstance(item, dict) for item in parsed_data):
cookies = parsed_data
else:
cookies = []
r = requests.Session()
for cookie in cookies:
r.cookies.update(cookie)
headers = {
'User-Agent' : 'my_user_agent'
}
r.get(url, headers=headers)
So, I solved it, the final code for those who needs it :
import requests
import json
url = 'https://steamcommunity.com/inventory/steamid/730/2?&count=5000'
with open('cookies.json', 'r') as f:
json_data = f.read()
parsed_data = json.loads(json_data)
if isinstance(parsed_data, list) and all(isinstance(item, dict) for item in parsed_data):
cookies = parsed_data
else:
cookies = []
session = requests.Session()
for cookie in cookies:
session.cookies.set(cookie['name'], cookie['value'])
headers = {
'User-Agent' : 'my_user_agent'
}
response = session.get(url)
print(response.text)
#Getting the whole inventory page content
and you don't need to change any data in your 'cookies.json' (I wrote that you need above)