人生苦短,我學python之python+selenium 隨機產生手機號碼和身份證

來源:互聯網
上載者:User

標籤:odi   lob   range   end   __file__   號碼   hone   imp   ret   

# coding:utf-8
import os
import random
import random
import string
import time
from datetime import date, datetime, timedelta
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
print BASE_DIR
DC_PATH = ‘E:\\zsjj\\‘ + "districtcode.txt"
print (DC_PATH)

# 隨機產生手機號碼
def createPhone():
prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "153",
"155", "156", "157", "158", "159", "186", "187", "188"]
return random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8))


# 隨機產生社會安全號碼
def getdistrictcode():
with open(DC_PATH) as file:
data = file.read()
districtlist = data.split(‘\n‘)
for node in districtlist:
# print node
if node[10:11] != ‘ ‘:
state = node[10:].strip()
if node[10:11] == ‘ ‘ and node[12:13] != ‘ ‘:
city = node[12:].strip()
if node[10:11] == ‘ ‘ and node[12:13] == ‘ ‘:
district = node[14:].strip()
code = node[0:6]
codelist.append({"state": state, "city": city, "district": district, "code": code})


def gennerator():
global codelist
codelist = []
if not codelist:
getdistrictcode()
id = codelist[random.randint(0, len(codelist))][‘code‘] # 地區項
id = id + str(random.randint(1930, 2013)) # 年份項
da = date.today() + timedelta(days=random.randint(1, 366)) # 月份和日期項
id = id + da.strftime(‘%m%d‘)
id = id + str(random.randint(100, 300)) # ,順序號簡單處理

i = 0
count = 0
weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] # 權重項
checkcode = {‘0‘: ‘1‘, ‘1‘: ‘0‘, ‘2‘: ‘X‘, ‘3‘: ‘9‘, ‘4‘: ‘8‘, ‘5‘: ‘7‘, ‘6‘: ‘6‘, ‘7‘: ‘5‘, ‘8‘: ‘5‘, ‘9‘: ‘3‘,
‘10‘: ‘2‘} # 校正碼映射
for i in range(0, len(id)):
count = count + int(id[i]) * weight[i]
id = id + checkcode[str(count % 11)] # 算出校正碼
return id


print createPhone()
print gennerator()

人生苦短,我學python之python+selenium 隨機產生手機號碼和身份證

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.