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])