Python3 simulates website logon and python3 logon website

Source: Internet
Author: User

Python3 simulates website logon and python3 logon website

#! /Usr/bin/env python #-*-coding: gb2312-*-# _ author __= "zhaowei" ''' log on to the Zhengzhou Provident Fund website to query the month of the deposit. ''' From html. parser import HTMLParserimport urllibimport http. cookiejarimport stringimport rehosturl = 'HTTP: // www.zzgjj.com/index.asp'posturl = 'HTTP: // www.zzgjj.com/user/login.asp'cj = http. cookiejar. cookieJar () cookie_support = urllib. request. HTTPCookieProcessor (cj) opener = urllib. request. build_opener (cookie_support, urllib. request. HTTPHandler) urllib. request. install_opener (opener) h = urllib. reque St. urlopen (hosturl) headers = {'user-agent': 'mozilla/5.0 (Windows NT 10.0; WOW64; rv: 38.0) Gecko/20100101 Firefox/123456', 'Referer ': 'http: // www.zzgjj.com/index.asp'your postdata = {'selectlb': '1', # logon mode, ID card 2, account 1 'username': '000000', # provident fund account 'radename ': 'zhao wei', 'mm': '000000', 'submit322': 'confirmed'} postData = urllib. parse. urlencode (postData, encoding = 'gbk '). encode ('gb2312') # Because post contains Chinese characters, you need to encode the url before using g Bk encodes the string. Request = urllib. request. request (posturl, postData, headers) response = urllib. request. urlopen (request) text = response. read () html = text. decode ('gbk') hgjj_last_data = re. findall ('<td> <p> pay to month: </p> (\ s *) </td> (\ s *) <td> (. *?) </Td> ', html) # use a regular expression to match the returned month print (hgjj_last_data [0] [2])

 

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.