Check the Python 3.3 code for the progress query for the Hong Kong and Macau Pass. Use the socket to request the relevant website, get the results and use the regular to find out the progress of processing. In fact, with URLLIB code will be more concise, but at that time is not familiar with urllib~
Directly on the code:
ImportSocketImportRe" "Guangdong Provincial Public Security Bureau entry-Exit government service network passport, pass processing progress inquiry. Parse URL format for http://www.gdcrj.com/wsyw/tcustomer/tcustomer.do?&method=find&applyid= ID number construct socket request Web page HTML, Match the query results with regular matches" "defGethtmlbyidentityid (Identityid): s=Socket.socket (socket.af_inet, socket. SOCK_STREAM) Host='www.gdcrj.com'; Suburl='/wsyw/tcustomer/tcustomer.do?&method=find&applyid={0}'Port= 80; Remote_ip=Socket.gethostbyname (Host) S.connect ((REMOTE_IP, port))Print('"INFO": Socket connection succeeded') Message='GET'+ Suburl.format (Identityid) +'Http/1.1\r\nhost:'+ Host +'\r\n\r\n' #Str 2 bytesM_bytes = Message.encode ('Utf-8') #Send bytesS.sendall (m_bytes)Print('"INFO": Remote download ...') Recevstr="' whileTrue:#Return bytesRecev = S.RECV (4096) #bytes 2 StrRecevstr + = recev.decode (encoding ='Utf-8', errors ='Ignore') if notrecev:s.close ()Print('"INFO": Remote download page Complete') Break returnRecevstr" "use regular expressions to find the query results from the HTML content of the Web page you get from the previous step" "defgetresultfromhtml (HTMLSTR): Linebreaks= Re.compile (r'\n\s*') Space= Re.compile ('( )+') Resultreg= Re.compile (r'\<td class= "News_font" \> ([^<td]+] \</td\>', Re. MULTILINE)#remove newline characters and spacesHtmlstr = Linebreaks.sub ("', htmlstr) htmlstr= Space.sub (' ', Htmlstr)#match the results of the queryresult =Resultreg.findall (HTMLSTR) forResinchResult:Print(Res.strip ())if __name__=='__main__': Identityid= Input ('Enter your ID number (only for residents in Guangdong province):') Try: Identityid=Int (Identityid)Print('"INFO": Start query') HTML=Gethtmlbyidentityid (Identityid) getresultfromhtml (HTML)Print('"INFO": Query succeeded') except: Print('"WARN": Enter illegal') input ('"INFO": Press any key to exit')
Python code query The progress of Hong Kong-Macau Pass