Life is short, I learn python python+selenium randomly generated mobile phone number and ID card

Source: Internet
Author: User

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

# randomly generated mobile phone number
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))


# Randomly generated ID number
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 '] # Region entry
id = id + str (random.randint (1930, 2013)) # Year Item
da = date.today () + Timedelta (Days=random.randint (1, 366)) # Month and date entries
id = id + da.strftime ('%m%d ')
id = id + str (random.randint (100, 300)) #, sequential number simple processing

i = 0
Count = 0
Weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] # Weight entry
Checkcode = {' 0 ': ' 1 ', ' 1 ': ' 0 ', ' 2 ': ' X ', ' 3 ': ' 9 ', ' 4 ': ' 8 ', ' 5 ': ' 7 ', ' 6 ': ' 6 ', ' 7 ': ' 5 ', ' 8 ': ' 5 ', ' 9 ': ' 3 ',
' 10 ': ' 2 '} # Check code mapping
For I in range (0, Len (ID)):
Count = count + int (id[i]) * Weight[i]
id = id + checkcode[str (count% 11)] # Check Code
Return ID


Print Createphone ()
Print Gennerator ()

Life is short, I learn python python+selenium randomly generated mobile phone number and ID card

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.