Reputation: 45
Is it possible to rotate different cookie specifications per specific request?
So let's say i have:
my_cookies = {"user": '100017',"TD": '4asdfaf3ALJfIP5dA-1'}
my_cookies2 = {"user": '100011',"TD": '4asdfafds%3ALJfIP5dA-2'}
How can i rotate between these two? I have read documentation on CookieJar, but haven't been able to find specific documentation on this problem.
Regards,
Durk
Upvotes: 2
Views: 406
Reputation: 21361
Yes.
Craete a list of Cookies and then use random.choice(all_cookies)
to send randomly selected cookie.
import random
all_cookies = [{"user": '100015407',"xs": '49%3ALJfIP5dA-1'}, {"user": '100015408',"xs": '49%3ALJfIP5dA-2'}]
yield Request(url, cookies = random.choice(all_cookies) , callback = call_back_func_here)
Upvotes: 2