日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python提取身份证信息_Python3 简单抓取身份证地址信息

發(fā)布時間:2024/8/1 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python提取身份证信息_Python3 简单抓取身份证地址信息 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

爬取接口 Ip138.com

def getInfo(idCard):

con = http.client.HTTPConnection("qq.ip138.com", 80)

con.request("GET", "/idsearch/index.asp?action=idcard&userid=" + idCard + "&B1=%B2%E9+%D1%AF")

rpons = con.getresponse()

resultText = rpons.read().decode("Gb2312")

rsgx = r'align="right">部分或全部現(xiàn)為:(.*?)

reseach = re.split(rsgx, resultText, 0)

area = ""

if (reseach.__len__() >= 2):

area = reseach[1].replace(" ", "")

else:

rsgx = r'valign="top" align="right">發(fā)?證?地:(.*?)

reseach = re.split(rsgx, resultText, 0)

if (reseach.__len__() >= 2):

area = reseach[1].replace(" ", "")

return area

###檢測指定的身份證號是否存在#############

def getReidsExit(filed):

redisClient = redis.StrictRedis(host='192.168.12.243', port=6379, password='fuyinhy123', db=0)

rs = redisClient.hexists("sys_card_area_map", filed)

return rs

###生成sql腳本文件 用于更新到線上數(shù)據(jù)庫

def createSQl(fileName):

createTime = time.strftime("%Y%m%d%H%M%S", time.localtime())

filepath = os.getcwd() + "/" + fileName

fileOutPath = os.getcwd() + "/sql-" + createTime + ".txt"

file = open(file=filepath, mode='r', encoding="utf-8")

fileOut = open(file=fileOutPath, mode='w', encoding="utf-8")

lines = file.readlines()

for line in lines:

idcard = line.replace("\n", "")

idcard6 = idcard[0:6]

if (not getReidsExit(idcard6)):

areaw = getInfo(idcard)

print(idcard + "----" + areaw)

fileData = "insert into arc_sys_card_area(card_id,card_area) VALUES('" + idcard6 + "','" + areaw + "');"

print(fileData)

fileOut.write(fileData + "\n")

fileOut.close()

file.close()

####匹配數(shù)據(jù) ########文本分割使用##############################

def createIdCardInfo(fileName):

createTime = time.strftime("%Y%m%d%H%M%S", time.localtime())

filepath = os.getcwd() + "/" + fileName

fileOutPath = os.getcwd() + "/cardinfoarea-" + createTime + ".txt"

file = open(file=filepath, mode='r', encoding="utf-8")

fileOut = open(file=fileOutPath, mode='w', encoding="utf-8")

lines = file.readlines()

for line in lines:

idcard = line.replace("\n", "")

datas = idcard.split()

if (len(datas) >= 3):

idNoCard = datas[2]

idcard6 = idNoCard[0:6]

areaw = getInfo(idNoCard)

print(idcard + "\t" + areaw)

fileData = idcard + "\t" + areaw

fileOut.write(fileData + "\n")

else:

print("erro data")

fileOut.close()

file.close()

##############################################啟動########################################

if __name__ == "__main__":

params = sys.argv

if (params[1] == "-sql"):

createSQl(params[2])

elif (params[1] == "-card"):

createIdCardInfo(params[2])

else:

print("==========Help=============")

print("-sql create sql scripy file")

print("-card create cardInfo File")

總結(jié)

以上是生活随笔為你收集整理的python提取身份证信息_Python3 简单抓取身份证地址信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。