Answer the question
In order to leave comments, you need to log in
How to import cookies from a file in requests?
I need to import cookies from a file in requests and send the request.
def cookies_from_file(cookie_dir):
with open(cookie_dir) as file:
cookies_data = file.read().replace('\n','').split(';')
cookies_dic = {}
for x in cookies_data:
key = x.split('=')[0]
value = x.split('=')[1]
cookies_dic[key]=value
return cookies_dic
cookies = cookies_from_file(cookie_dir)
response = requests.get(link4,headers=headers,cookies=cookies, timeout=2).text
soup = BeautifulSoup(response, 'html.parser')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question