Extracting ViewState and other ASP .Net params
This is a very simple function for extracting any ASP .Net page state value such as __VIEWSTATE or __EVENTVALIDATION. These values are necessary when scraping some websites.
Public Shared Function ExtractDotNetData(ByVal strData As String, ByVal strStateName As String, ByVal strDelimiter As String) As String
Dim iStateNamePosition As Integer = strData.IndexOf(strStateName)
If iStateNamePosition < 0 Then Return ""
Dim iStateValuePosition As Integer = strData.IndexOf(strDelimiter, iStateNamePosition)
If iStateValuePosition < 0 Then Return ""
Dim iStateStartPosition As Integer = iStateValuePosition + strDelimiter.Length
Dim iStateEndPosition As Integer = strData.IndexOf("""", iStateStartPosition)
Return HttpUtility.UrlEncodeUnicode(strData.Substring(iStateStartPosition, iStateEndPosition - iStateStartPosition))
End Function
strViewState = ExtractDotNetData(strResponseData, "__VIEWSTATE", "value=""")
strEventValidation = ExtractDotNetData(strResponseData, "__EVENTVALIDATION", "value=""")
- Download this code: ExtractDotNetData.txt