回复 80楼 TonyDeng
请楼主再找几个电话列表,分析一下网页内容,这样写出的代码才能通用,用一个网页写出的代码内容毕竟是有限的。
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