Created
June 26, 2022 14:12
-
-
Save lyf-is-coding/52f04b5c43f3cb7adcb09645801e14a3 to your computer and use it in GitHub Desktop.
Python find __RequestVerificationToken
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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