Python carries a cookie to access the website (Python Interface test post)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.