标题:版主,来改标题(快速提取电话号码)
只看楼主
bccn201203
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:680
专家分:1140
注 册:2012-3-14
得分:0 
回复 80楼 TonyDeng
请楼主再找几个电话列表,分析一下网页内容,这样写出的代码才能通用,用一个网页写出的代码内容毕竟是有限的。
2012-10-22 14:00
bccn201203
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:680
专家分:1140
注 册:2012-3-14
得分:0 
回复 79楼 taohua300
固定位置的电话号码,提取后怎么会不完整。
2012-10-22 14:02
bccn201203
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:680
专家分:1140
注 册:2012-3-14
得分:0 
http://www.
这个地址也是电话黄页,但格式完全不一样
2012-10-22 14:20
jsyg
Rank: 2
等 级:论坛游民
威 望:1
帖 子:75
专家分:38
注 册:2012-10-20
得分:9 
学习、学习!
但就象看天书一样,高手们真是太高了!
高!实在是高!
2012-10-22 19:17
taohua300
Rank: 12Rank: 12Rank: 12
来 自:光
等 级:贵宾
威 望:14
帖 子:1636
专家分:3906
注 册:2009-3-11
得分:0 
来回想了想
电话企业列表里的电话号码有点问题
如果前面有国际区号,那么国内区号最前面的0应该省略
而且
手机号码前面没有国际区号,是不是说跨国拨打手机的时候就不用加国际区号了 ?
这又是我犯下的一个错误
阴差阳错的下载了这个网页

个性太多,无法显示
2012-10-23 09:09
taohua300
Rank: 12Rank: 12Rank: 12
来 自:光
等 级:贵宾
威 望:14
帖 子:1636
专家分:3906
注 册:2009-3-11
得分:0 
本来是想看看有没有人跟我的想法类似,想看看他是怎么处理的
或是能找到个比较完美的思路
不过目前还没有发现
综合起来T版的比较好点
我发一下我刚写的
抛砖引玉
程序代码:
Clear 

Declare Long GetTickCount In Win32api
nSecond = GetTickCount()
lcStr = Strconv(Filetostr('ww.htm'), 2)
lcHtml = Chrtran(lcStr, '0123456789-_', '')
lcStr = Chrtran(lcStr, lcHtml, Replicate('|', Len(lcHtml)))
Do While .T.
    lcStr = Strtran(lcStr, '||', '|')
    If At('||', lcStr) == 0
        Exit
    Endif
Enddo
lnCount = Getwordcount(lcStr, '|')
Strtofile('', 'nums.txt')

lcArea = ",0311,0312,0313,0314,0315,0316,0317,0318,0319,0310,0335,0349,0351,0352,0353,0354," + ;
"0355,0356,0357,0358,0359,0350,0371,0372,0373,0374,0375,0376,0377,0378,0379,0370," + ;
"0391,0392,0393,0394,0395,0396,0397,0398,0411,0412,0414,0415,0416,0417,0418,0419," + ;
"0421,0427,0429,0431,0432,0433,0434,0435,0436,0437,0438,0439,0440,0448,0451,0452," + ;
"0453,0454,0455,0456,0457,0458,0459,0464,0467,0468,0469,0471,0472,0473,0474,0475," + ;
"0476,0477,0478,0479,0470,0482,0483,0511,0512,0513,0514,0515,0516,0517,0518,0519," + ;
"0510,0523,0527,0531,0532,0533,0534,0535,0536,0537,0538,0539,0530,0543,0546,0631," + ;
"0632,0633,0634,0635,0551,0552,0553,0554,0555,0556,0557,0558,0559,0550,0561,0562," + ;
"0563,0564,0565,0566,0571,0572,0573,0574,0575,0576,0577,0578,0579,0570,0580,0591," + ;
"0592,0593,0594,0595,0596,0597,0598,0599,0711,0712,0713,0714,0715,0716,0717,0718," + ;
"0719,0710,0722,0724,0728,0731,0734,0735,0736,0737,0738,0739,0730,0743,0744,0745," + ;
"0746,0750,0751,0752,0753,0754,0755,0756,0757,0758,0759,0760,0762,0763,0766,0768," + ;
"0769,0660,0662,0663,0668,0771,0772,0773,0774,0775,0776,0777,0778,0779,0770,0791," + ;
"0792,0793,0794,0795,0796,0797,0798,0799,0790,0701,0812,0813,0816,0817,0818,0825," + ;
"0826,0827,0831,0832,0833,0834,0835,0836,0837,0838,0839,0830,0851,0852,0853,0854," + ;
"0855,0856,0857,0858,0859,0871,0872,0873,0874,0875,0876,0877,0878,0879,0870,0883," + ;
"0886,0887,0888,0691,0692,0891,0892,0893,0894,0895,0896,0897,0898,0911,0912,0913," + ;
"0914,0915,0916,0917,0919,0931,0932,0933,0934,0935,0936,0937,0938,0939,0930,0941," + ;
"0943,0951,0952,0953,0954,0955,0971,0972,0973,0974,0975,0976,0977,0979,0970,0991," + ;
"0992,0993,0994,0995,0996,0997,0998,0999,0990,0901,0902,0903,0906,0908,0909,010," + ;
"021,022,023,025,027,028,029,020,"

For i = 1 To lnCount
    lcNum = Getwordnum(lcStr, i, '|')
    If At('-', lcNum, 2) != 0 && 大于等于两个‘-’不认为是电话号码
        Loop
    Endif
    If At('_', lcNum) != 0
        Loop
    Endif
    **    如果号码为7位或是8位并且第一位数字不为0,认为是固话号码
    If (Len(lcNum) == 7 Or Len(lcNum) == 8) And Left(lcNum,1) != '0' And At('-', lcNum) == 0
        Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .t.)
    Else
*!*        关于区号的处理
*!*        可以预先整理国内全部区号放在字符串中
*!*        http://zh./wiki/%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD%E5%A2%83%E5%86%85%E5%9C%B0%E5%8C%BA%E7%94%B5%E8%AF%9D%E5%8C%BA%E5%8F%B7
*!*       
        Do Case
            Case Len(lcNum) == 10 && 固话7位+3位区号
                If At(',' + Left(lcNum, 3) + ',', lcArea) != 0 And Substr(lcNum, 4, 1) != '0'
                    Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .t.)
                Endif
               
            Case Len(lcNum) == 11 && 可能是手机号,8+3固话,7+4固话或者7+3+1位‘-’固话
                If At('-', lcNum) == 0
                    If At(',' + Left(lcNum, 3) + ',', lcArea) != 0
                        If Substr(lcNum, 4, 1) != '0' && 8+3固话
                            Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                        Endif
                    Else
                        If At(',' + Left(lcNum, 4) + ',', lcArea) != 0 And Substr(lcNum, 5, 1) != '0'
                            Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.) &&7+4
                        Else
                            lcPhone3 = '135,136,137,138,139,147,150,151,152,157,158,159,182,183,187,188,130,131,132,145,155,156,185,186,133,153,180,181,189,134,'
                            If At(Left(lcNum, 3) + ',', lcPhone3) != 0 &&手机号码
                                Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                            Endif
                        Endif
                    Endif
                Else
                    If At(',' + Left(lcNum, 3) + ',', lcArea) != 0 And Substr(lcNum, 4, 1) == '-' And Substr(lcNum, 5, 1) != '0'
                    *7+3+1位‘-’固话
                        Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                    Endif
                Endif
               
            Case Len(lcNum) == 12&& 4+8或者4+1+7或者3+1+8
                If At('-', lcNum) != 0&& 3+1+8
                    If At(',' + Left(lcNum, 3) + ',', lcArea) != 0 And Substr(lcNum, 4, 1) == '-' And Substr(lcNum, 5, 1) != '0'
                        Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                    Else
                        If At(',' + Left(lcNum, 4) + ',', lcArea) != 0 And Substr(lcNum, 5, 1) == '-' And Substr(lcNum, 6, 1) != '0'&& 4+1+7
                            Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                        Endif
                    Endif
                Else
                    If At(',' + Left(lcNum, 4) + ',', lcArea) != 0 And Substr(lcNum, 5, 1) != '0' &&4+8
                        Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                    Endif
                Endif
               
            Case Len(lcNum) == 13 && 4+1+8
                If At(',' + Left(lcNum, 4) + ',', lcArea) != 0 And Substr(lcNum, 5, 1) == '-' And Substr(lcNum, 6, 1) != '0'&& 4+1+7
                    Strtofile(lcNum + Chr(13) + Chr(10), 'nums.txt', .T.)
                Endif
        Endcase
    Endif
Next 
Modify File nums.txt


个性太多,无法显示
2012-10-23 11:09
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
把规则写在代码中,不是个了局,即使对了,那样的代码也很难维护,少许改动就能要你的命。

授人以渔,不授人以鱼。
2012-10-23 13:03
taohua300
Rank: 12Rank: 12Rank: 12
来 自:光
等 级:贵宾
威 望:14
帖 子:1636
专家分:3906
注 册:2009-3-11
得分:0 
以下是引用TonyDeng在2012-10-23 13:03:34的发言:

把规则写在代码中,不是个了局,即使对了,那样的代码也很难维护,少许改动就能要你的命。
又不是大项目,不至于

个性太多,无法显示
2012-10-23 13:18
bccn201203
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:680
专家分:1140
注 册:2012-3-14
得分:0 
回复 86楼 taohua300
至于这么麻烦吗,既然是提取电话号码,就要忠实于原作,你那样修改,未必就能达到满意的结果。
你的电话区号是否包括海南省三沙市的区号在内。

[ 本帖最后由 bccn201203 于 2012-10-23 13:54 编辑 ]
2012-10-23 13:53
bccn201203
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:680
专家分:1140
注 册:2012-3-14
得分:0 
计算机; 办公设备; 智能化设备; 系统集南京超想科技开发有限公司
成立公司于2000年11月,主要从事计算机、通信、办公自动化产品的销售服务以及计算机网络、智能化小区、通信、自动化控制等工程项目的设计、安装。
电话:86-25-84714861地址:中国江苏 南京市 珠江路273号-6
这个号码楼主如何处理。
楼主能否帖出电话号码提取结果
2012-10-23 14:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-383645-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.779806 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved