Skip to main content

Python requests package

requests package

create session

with requests.Session() as s:
r = s.get(url=url, verify=False, proxies=proxies)

# extract the tracking id and update it
cookies = requests.utils.dict_from_cookiejar(s.cookies)
trackingId = cookies['TrackingId'] + "New"
sessionId = cookies['session']

cookies = {
'TrackingId': trackingId,
'session': sessionId
}

# clear the cookie and
s.cookies.clear()
# update the session cookie with the updated cookie
s.cookies.update(cookies)
r = s.get(url=url, verify=False, proxies=proxies)
if r.status_code == 500:
password_extracted += chr(j)
sys.stdout.write('\r' + 'Probing: ' + password_extracted)
sys.stdout.flush()
break
else:
sys.stdout.write('\r' + 'Probing: ' + password_extracted + chr(j))
sys.stdout.flush()

check the response time

resp = s.get(url=url, verify=False, proxies=proxies)
print(f'response time is: {resp.elapsed.total_seconds()}')

Handling Cookies

With requests.Session() as s
resp = s.get(url=url, verify=False, proxies=proxies)
cookie = resp.cookies.get_dict()

Iterating through cookies

for cookie in cookies:
print(f"domain: {cookie.domain}")
print(f"name: {cookie.name}")
print(f"value {cookie.value}")

Create a new cookie jar and set the value in the cookie

cookies_jar = requests.cookies.RequestsCookieJar()
cookies_jar.set("session", "value of the session from the previous request")
cookies_jar.set("TrackingId","some payload")

Clear the session cookies

Clear the session cookies before adding the updated cookies.

session.cookies.clear()
resp = session.get(url=url, verify=False, proxies=proxies, cookies=cookies_jar)