Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Created June 26, 2022 14:12
Show Gist options
  • Save lyf-is-coding/52f04b5c43f3cb7adcb09645801e14a3 to your computer and use it in GitHub Desktop.
Save lyf-is-coding/52f04b5c43f3cb7adcb09645801e14a3 to your computer and use it in GitHub Desktop.
Python find __RequestVerificationToken
# Make a request to the website to get the html file
# Parse the html file and find the __RequestVerificationToken then use it to make other requests :)
# __RequestVerificationToken always stay in input tag
# example:
# <input name="__RequestVerificationToken" type="hidden" value="cm486PKVb3TS04HQEjXhoYcwjQxTXgPfdJLnqOJ8NOqXWlJ_hwjdCEYmPxfLYbkRudBFctFKcXchfTHSgPlRq4xMGmGcIZqZivduIxmvsDs1">
# read more about __RequestVerificationToken
# https://blog.stevensanderson.com/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/
import requests
from bs4 import BeautifulSoup
s = requests.Session()
url = "https://someurl.com"
response = s.get(url)
token = BeautifulSoup(response.text, "html.parser").find("input",{"name":"__RequestVerificationToken"})["value"]
print(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment