why isn't this python regex statement returning my viewstate information?
def ExtractViewState(string):
m = re.match("__viewstate[^>]+value=\"\(\?<Value>[^\"]*\)", string, re.IGNORECASE)
return m.group(0)
I think I'm missing something, but it m keeps returning None. Blagh.
UPDATE:
<开发者_运维问答;input type="hidden" name="__VIEWSTATE" value="5vzj+3s4pEHFJUQoOJbZicZdf+k2bi0uiXeIxMNTxjocu0FLzTXEI8pEcQy/V4r1vtIP6G/E0/j0C5TwvhaWdW1wJVGwGKfO26gvQk9O0zsxy5NBpx+PlfL5h7nlnAp+GmAIwdjLWxRFFbhxaOfH+yZQKfkzshBvE7xogxrTnrrlF22BiENHdWHuMqeGYb4AUfvbbJ2psQOwTTOF6meAjszLtaAxBVTgun4gVsGOKUDqasgzyYn7AsxsJ4rJ3S/64YU2sUwAsvCD1d0X3Q8bGiwriRU/pAo31xn4SfhP8dk22QbhFbVpvIwl3WGTxohL" />
should just return the text between in the value attribute:
"5vzj+3s4pEHFJUQoOJbZicZdf+k2bi0uiXeIxMNTxjocu0FLzTXEI8pEcQy/V4r1vtIP6G/E0/j0C5TwvhaWdW1wJVGwGKfO26gvQk9O0zsxy5NBpx+PlfL5h7nlnAp+GmAIwdjLWxRFFbhxaOfH+yZQKfkzshBvE7xogxrTnrrlF22BiENHdWHuMqeGYb4AUfvbbJ2psQOwTTOF6meAjszLtaAxBVTgun4gVsGOKUDqasgzyYn7AsxsJ4rJ3S/64YU2sUwAsvCD1d0X3Q8bGiwriRU/pAo31xn4SfhP8dk22QbhFbVpvIwl3WGTxohL"
You have a few issues:
import re
def ExtractViewState(string):
# re.match looks only at the **beginning** of the string
# dont escape the `( .. )` those capture the group
m = re.search("__viewstate[^>]+value=\"([^\"]*)", string, re.IGNORECASE)
# group(0) is the whole match, you want the 1st capture group
return m.group(1)
Three problems.
You need
re.search
, notre.match
.You need
(?P<...>)
, not just(?<...>)
.You have more backslashes than you need.
re.search("__viewstate[^>]+value=\"(?P<Value>[^\"]*)", s, re.IGNORECASE)
works for me.
精彩评论