Recently, when using your own research performance testing tool, I thought of using Python to continuously send data to the server as a concurrency test. The approximate situation is as follows:
#Coding=utf-8ImportUrllib2ImportUrllibImportCookielibImportOSImportThreadingImport TimeclassHB:defAdd_cookie_login (self,username): Self.user=username Cookiejar=Cookielib. Cookiejar () Urlopener=Urllib2.build_opener (urllib2. Httpcookieprocessor (Cookiejar)) headers={ "user-agent":"mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"} data={ "LoginName": Self.user,"Password":'111111', 'Remember': 1} postdata=urllib.urlencode (data) Url_1='Http://test.reg.haibian.com/login/ajax_login'Request=Urllib2. Request (url_1,postdata,headers) URL=Urlopener.open (Request)Printurl.info () page=url.read () URL= Urlopener.open ('Http://test.www.haibian.com/home/index') #request = Urllib2. Request (URL) #URL = urlopener.open (request)page =url.read () URL= Urlopener.open ('http://test.www.haibian.com/course/study?chapter_id=8540&course_id=1095&class_id=1433152942& date_id=48946') Page=Url.read ()PrintpagedefUsers (self): F= Open ('Student_email.txt') Data=F.readlines () forUserinchdata:self.add_cookie_login (user) Break #Print User, Passif __name__=='__main__': L=HB () l.users ()
is through several packages of Python, then sends the data to the server, and then the login cookie returned by the server accesses the other pages of the site.
Python carries a cookie to access the website (Python Interface test post)