Answer the question
In order to leave comments, you need to log in
How to forward cookies in a Python request?
I want to parse the forum of one game project, but there is protection from React Su, in general, on some forum I found a way to bypass this protection simply by waiting 5 seconds and throwing cookies that come in the first request into the next request.
I was able to get these cookies and put them in an array, but how do I now forward them to a forum request?
Forum response code with disabled JS:
<!DOCTYPE html>
<html>
<script src="/vddosw3data.js"></script>
<body>
<div w3-include-html="/5s.html"></div>
<noscript><h1 style="text-align:center;color:red;"><strong>Please turn JavaScript on and reload the page.</strong></h1></noscript>
<script>
w3IncludeHTML();
</script>
<script language="javascript">document.cookie="REACTLABSPROTECTION=08a98f1fc56b35b872512a856a242501 ; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";setTimeout("location.href='http://gta-trinity.ru:80/forum/index.php?/topic/192463-afpd-%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0-%D0%BE%D1%82%D1%87%D0%B5%D1%82%D0%BD%D0%BE%D1%81%D1%82%D0%B8/';",5000);</script>
<center>
<br />
<br />
<center/>
</body>
</html>
import requests
import re
from bs4 import BeautifulSoup
s = requests.Session()
index = s.get("http://gta-trinity.ru/forum/", timeout=10).text
index = BeautifulSoup(index, "html.parser")
cookies_info = re.findall('document.cookie="(.*)";set', str(index.find_all("script")[2]))[0].split(';')
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