If you are developing applications for mobile phones, such as getting a list of blacklisted phone numbers from the cloud center, however, these phone numbers are returned as a text file, and you need to analyze these lines of text into the number of telecom vendors, phone numbers, notes, tags, In fact, this process is to convert the serialized information into structured information, so that it can be more convenient to handle, such as the phone number out as a comparison of interception.
Example:
Text = "" "18701808546 1 user scam number (2015-08-24)
15396989999 1 -User harassment number (2015-08-23)
15992460848 1 -user scam number (2015-08-23)
15625759163 1 users promotion, intermediary (2015-08-23)
15994768049 1 users send scam information (2015-08-23)
18670826757 1 -user scam number (2015-08-22)
13141465810 1 -user scam number (2015-08-22)
13860039526:1 bit user fraud number (2015-08-22) "" "
Entries = Re.split ("\n+", text)
Print (entries)
L = [Re.split (":?", entry, 2) for entry in entries]
Print (L)
Print (' \ n output phone number:')
For phone in L:
Print (Phone[0])
The resulting output is as follows:
[' 18701808546 1bit user scam number(2015-08-24) ', ' 15396989999 1User Harassment number(2015-08-23) ', ' 15992460848 1bit user scam number(2015-08-23) ', ' 15625759163 1user promotion, intermediary(2015-08-23) ', ' 15994768049 1users to send fraudulent information(2015-08-23) ', ' 18670826757 1bit user scam number(2015-08-22) ', ' 13141465810 1bit user scam number(2015-08-22) ', ' 13860039526:1bit user scam number(2015-08-22) ']
[[' 18701808546 ', ' 1bit user scam number' , ' (2015-08-24) ', [' 15396989999 ', ' 1User Harassment number' , ' (2015-08-23) ', [' 15992460848 ', ' 1bit user scam number' , ' (2015-08-23) ', [' 15625759163 ', ' 1user promotion, intermediary' , ' (2015-08-23) ', [' 15994768049 ', ' 1users to send fraudulent information' , ' (2015-08-23) ', [' 18670826757 ', ' 1bit user scam number' , ' (2015-08-22) ', [' 13141465810 ', ' 1bit user scam number' , ' (2015-08-22) ', [' 13860039526 ', ' 1bit user scam number' , ' (2015-08-22) ' ]
Output Phone Number:
18701808546
15396989999
15992460848
15625759163
15994768049
18670826757
13141465810
13860039526
In this example, re.split ("\n+", text) is used to remove multiple lines of empty lines, so that all text is close together, using [Re.split (":?", entry, 2) for entry in Entries] to split each line of text into usable information format, and up to three groups of ways, and finally by traversing the list l can get all the phone number results, so when there is a caller display, You can tell if the number is in these lists, if you hang up the phone, block all harassment calls, advertising calls, improve the efficiency of the whole society, like this annoying phone will always interrupt you during the working hours, when you just sleep in bed when you call, or in the process of driving constantly, bring a lot of problems.
Cai Junsheng qq:9073204 Shenzhen
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
3.2.5.4 Analysis Blacklist