python 爬虫 ——获取__VIEWSTATE 与__EVENTVALIDATION

用正则表达式匹配出来的;

# 获取表单VIEWSTATE,EVENTVALIDATION的值 参数r是html

def get_VIEWSTATE(r):
pattern1=r'VIEWSTATE\".*value=\".*\"'
match=re.search(pattern1,r).group(0);
pattern2=r'VIEWSTATE\" id=\"__VIEWSTATE\" value=\"'
match1=re.split(pattern2,match);
return match1[1][:-1]; #返回_VIEWSTATE

def get_EVENTVALIDATION(r):
pattern1=r'EVENTVALIDATION\".*value=\".*\"'
match=re.search(pattern1,r).group(0);
pattern2=r'EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"'
match1=re.split(pattern2,match);
return match1[1][:-1]; #返回_EVENTVALIDATION

#############################

转载于:https://www.cnblogs.com/z-bear/p/9455255.html

你可能感兴趣的:(python,爬虫)