Punch out with Python

Source: Internet
Author: User
Tags python script

The company needs to submit a dynamic every day, in fact, similar to punch-in, but with the meaning of punch card, but it doesn't matter, in fact, with the card punch is exactly the same. This commit dynamic is to log into the company's project management system, then select the appropriate project, and then click on a button to submit it. Submit this dynamic, can be submitted for two days at a time, that is, today, in addition to today can be submitted, but also the submission of tomorrow, so that tomorrow can not be submitted. Of course, by tomorrow, you can submit the next day, because the day was submitted, of course, can also be submitted again. If you forget, the company will call or send a text message to remind me that one time I forgot. Later, in order to save trouble, wrote a python script to commit the dynamic.


Code is not long, directly paste code it!

import urllibimport urllib2import cookielibhosturl =  ' http://xxxx/yyyy/login.jsp ' CJ  = cookielib. Lwpcookiejar () cookie_support = urllib2. Httpcookieprocessor (CJ) Opener = urllib2.build_opener (COOKIE_SUPPORT, URLLIB2. HttpHandler)   urllib2.install_opener (opener)   h = urllib2.urlopen (Hosturl)   headers = {     ' user-agent '  :  ' mozilla/5.0  (windows nt  6.3; wow64; rv:49.0)  gecko/20100101 firefox/49.0 ',       ' Referer '  :  ' http://xxxx/yyyy/index.jsp '}  postdata = {     ' Login '  : user,       ' passwd '  : passwd,        ' Submit '  :  ' Commit '}postdata = urllib.urlencode (postdata)   request  = urllib2. Request (hosturl, postdata, headers)  &nbsP;response = urllib2.urlopen (Request)   text = response.read ()   day= ' Http://xxxx/yyyy/RW/gcsxgdt2.jsp? Rwdno=111222&userno=111&days=%bd%f1%c8%d5 ' day1= ' http://xxxx/yyyy/RW/gcsxgdt2.jsp? Rwdno=111222&userno=111&days=%c3%f7%c8%d5 ' F = urllib2. Request (Day) Response = urllib2.urlopen (f)   text = response.read ()    Print text.decode (' GB18030 ') print  ' ============================== ' f = urllib2. Request (Day1) Response = urllib2.urlopen (f)   text = response.read ()    Print text.decode (' GB18030 ')


The first thing you need is a simulated login, after the successful login, the above two connections directly to access a.


In the Log in section, you need to modify Hosturl, and then headers and postdata according to their own bag (you can use the Grab Bag tool or Firefox plug-in) to modify the data.

This article is from the "Sleep Blog" blog, please be sure to keep this source http://wujue.blog.51cto.com/11999347/1870073

Punch out with Python

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.