Not long ago, through the online access to a variety of information, has always wanted to use Python to achieve the function of analog login, through the CSDN Wanghai blog learned a little, but also can only be a fur, or fur are not counted.
Side of the data to write a small thing, at first want to write a program, through brute force + analog login Way to achieve the password to crack school card, what material, strong cracked face six-digit password of 1000000 kinds of attempts, it is difficult to crack a short time, another reason is the time of the violent attempt server side always problem, Codenamed 500, then stranded.
Now only to achieve a password to login a person's account, read first page information, specific consumption records related to the issue of paging, each page will be submitted a string of long strings, can not understand.
The code is as follows:
1 #-*-coding:utf-8-*-2 ImportRequests3 ImportRe4 classTOOl:5Removingfont=re.compile ('[\n]*?', Re. S)6 defreplace (self,x):7X=re.sub (Self.removingfont,"", X)8 returnX.strip ()9 classYKTCX:Ten def __init__(self): One ## #登录页的url ASelf.url ='http://ecard.jit.edu.cn/cxweb/Default.aspx' -Self.url2='http://ecard.jit.edu.cn/cxweb/information.aspx' - ## #有些网站反爬虫, here use headers to disguise the program as a browser theSelf.header = {'user-agent':'mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/30.0.1599.101 safari/537.36' } - ## #登录需要提交的表单 -Self.form_data = {'__lastfocus':"', - '__eventtarget':'Login', + '__eventargument':"', - '__viewstate':'/wepdwullte3njgxmtcwnzgpzbycagepzbycagspdxychgruzxh0bspnlkjmilflki3mijblr4bnoihpljnor68s6k+35qoa5p+ Liwrkzfm8z2dw6byhwffbvycaliwda9q3', + 'TextBox1':'xxxxxx',#fill in the website's online account number A 'TextBox2':'xxxxx',#Fill in the website password (after encryption) at '__eventvalidation':'/wewbakp05afcwls0blrbgls0fbzdakpypgactrg6xucnmozvj+yquz87xcafrth',} -self.form_data['TextBox1']='01305xxxx' -self.form_data['TextBox2']='xxxxx' -Self.tool=TOOl () - defLogin (self): -s =requests.session () inResponse = S.post (Self.url,data = Self.form_data,headers =Self.header) - #Print Response.content toR=s.get (self.url2,allow_redirects =False) + #Print R.content - ifr.status_code==200: the PrintSelf.name (r.content) +'\ n'+self.banji (r.content) +'\ n'+self.banknumber (r.content) +'\ n'+self.stuid (r.content) [1:] * Else: $ Print 'request error \ n'Panax NotoginsengR=s.get ('http://ecard.jit.edu.cn/cxweb/consumesele.aspx') - ifr.status_code==200: the #Print R.content + self.details (r.content) A the + deftitle (self,page): -Pattern=re.compile ('(<title>) (. *?) (</title>)') $result=Re.search (pattern,page) $ ifResult: - returnResult.group (1) - Else: the returnNone - defname (self,page):WuyiPattern=re.compile ('<span id= "Member_name" > (. *?) </span>', Re. S) theresult=Re.search (pattern,page) - ifResult: Wu returnResult.group (1) - Else: About returnNone $ defIdcard (self,page): -Pattern=re.compile ('<span id= "Identity_card" > (. *?) </span>', Re. S) -result=Re.search (pattern,page) - ifResult: A returnResult.group (1) + Else: the returnNone - defStuid (self,page): $Pattern=re.compile ('<span id= "Member_code" > (. *?) </span>', Re. S) theresult=Re.search (pattern,page) the ifResult: the returnResult.group (1) the Else: - returnNone in defBanji (self,page): thePattern=re.compile ('<span id= "Dept_description" > (. *?) </span>', Re. S) theresult=Re.search (pattern,page) About ifResult: the returnResult.group (1) the Else: the returnNone + defBanknumber (self,page): -Pattern=re.compile ('<span id= "Banknumber" > (. *?) </span>', Re. S) theresult=Re.search (pattern,page)Bayi ifResult: the returnResult.group (1) the Else: - returnNone - defDetails (self,page): thePattern=re.compile ('<td align= "center" ><font face= "song Body" color= "#000066" > (. *?) </font></td>', Re. S) theresults=Re.findall (pattern,page) the ifResults: the forIteminchResults: - #print Self.tool.replace (results[1]) the Printself.tool.replace (item) the Print"____________________-" the Else:94 returnNone the theA=yktcx () theA.login ()
Today level six score out, because forget the admission ticket number, want to use the number of students to traverse the implementation of different attempts, helpless http://www.chsi.com.cn/cet/this site's login some weird, only blame their own learned shallow bar, failed to do
A little practice on Python's analog login