Python Reptile notes [a] simulated users access the login form is submitted - the second time (7)

Encountered when you first sign in this issue, page verification different code and download the required identification code issues, said online search is called code synchronization problems. Found to be solved with a cookie, that cookie to introduce cookie can be achieved by the time stamp synchronization been tested and found open with the last cookie with a verification code page is the same. Login is submitting a form to the back-end server, then we can bind the cookie (the request timestamp post request and verification code verification code is the same, to solve the verification code synchronization) and then submit the form to sign, so the following to introduce this method (of course, this method is not resolved). The reason a little crash. Besides, after the first code issues.

 

Import http.cookiejar
 Import urllib
 Import Re 

# code pages get, that is src. 
= CaptchaUrl " HTTP: //xxxxxxxxxxxxxxValidateCode.aspx " 
# POST request address, web properties can be obtained by, for 2 form 3 before details see 
posturl = " HTTP: xxxxxxxxxxxxxxxxxxlogin_home.aspx " 
# bind the cookies to a opener cookie cookielib automatically manage 
the cookie = http.cookiejar.CookieJar () 
Handler = urllib.request.HTTPCookieProcessor (the cookie) 
opener = urllib.request.build_opener (Handler)
 # username and password 
username = ' xxxxxxx '
password = ' XXXXXXX ' 
# with openr address access codes, obtaining Cookie 
IMG = opener.open (CaptchaUrl) .read ()
 # save to local codes 
LOCATION = Open ( ' ./easy_code/checkcode.jpg ' , ' WB ' ) 
location.write (img) 
location.close () 
# open the saved picture input verification code, here you can switch to tesseract-orc recognition, but just started testing or use personally identifiable accurate point, before the identification function on a 
iNPUT = SecretCode ( ' enter the code: ' )
 # the capture configuration information form the network through f12 network acquisition, the following will indicate 
postData = {
 ' the __VIEWSTATE ' : '/wEPDwUKMTAzNTIzMjg1NWRk',
'__EVENTVALIDATION':'/wEdAAIKtHwTirT2Pt1uwYfKvQ1EZ5IuKWa4Qm28BhxLxh2oFA==',
'txt_asmcdefsddsd': username,
'txt_pewerwedsdfsdff': password,
'txt_sdertfgsadscxcadsad': SecretCode,
}
# 根据抓包信息 构造headers
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding':'gzip, deflate',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0',
}
# 生成post数据
data = urllib.parse.urlencode(postData).encode(encoding='UTF8'
request =Configured REQUEST request#)
urllib.request.Request (posturl, Data, headers)
 # Since the page is gb2312 encoding, it is necessary to decode 
Response = opener.open (Request) 
Result = response.read (). decode ( ' gb2312 ' )
 # after printing log pages 
Print (the Result)

The above information can be obtained form the network through F12> find the post (you only need to submit the form it)> parameters

__VIEWSTATE and __EVENTVALIDATION any two parameters need to fill out, or will be error, the rest is the account password verification code

 

Codes above pop up after I run an error message Object reference not set to an instance of an object. Upon inquiry said that a parameter is not filled in, after several tests found that, fgfggfdgtyuuyyuuckjg is a change in value, and then find its location in html and it found that the beginning of a null value, when you click on the password input, its value will follow you change the password, but also generated each time you enter this number is different, because we are directly login with post requests, it is impossible departure js the value of the acquisition (of course possible that I do not know if there are big brothers to solve be sure to contact). So this method to cool it, of course, the above method is absolutely feasible, for code synchronization is available, provided that you'd like to sign this site does not pit father's post set. In response to this question before I did not find there are kinds of cookie method, the next presentation.

 

 

Reference Gangster article

Sign post request using: http://www.cppcns.com/jiaoben/python/140695.html

__EVENTVALIDATION no parameter error reasons: https://www.cnblogs.com/Tony_2009/archive/2009/06/15/1503780.html

Three kinds of post requests idea: https://blog.csdn.net/qq_18698003/article/details/51591346

Guess you like

Origin www.cnblogs.com/dfy-blog/p/11566614.html