仿照版主的表格,再次将代码修改,现在出来的效果跟版主的一模一样了。运行时间:第一次:1236毫秒,有缓存后,17毫秒,看来读写表文件要比读写低级文件要快得多。
[ 本帖最后由 月沐庭轩 于 2012-10-28 16:06 编辑 ]
程序代码:
*!* 程序分为一个主程序模块,三个次程序模块 *!* 主程序模块***************************************************** starttime=SECONDS()*1000 CREATE CURSOR tqhdm (层次 N(1),代码 c(12),分类 c(3),名称 c(40),网址 c(150)) cc=2 websites="http://www.stats./tjbz/cxfldm/2011/41/4101.html" daima=SUBSTR(websites,RAT("/",websites)+1,4) INSERT INTO tqhdm VALUE(cc,daima,"4101","郑州市",websites) xiazai(websites) endtime=SECONDS()*1000 TIMES=endtime-starttime MESSAGEBOX("你所花费的时间为"+ALLTRIM(STR(TIMES,20))+"毫秒",64,"测试") SELECT tqhdm BROWSE *!* 主程序模块结束************************************************** *!* 下载HTML代码程序块********************************************* FUNCTION xiazai(website) LOCAL website,tempstr,daima, mingcheng test=CREATEOBJECT("MICROSOFT.XMLHTTP") test.OPEN([GET], website,.F.) test.SEND tempstr=test.responsetext *****市辖区代码,按照版主要求可以没有的,我这里加得很勉强。 shiqu=STREXTRACT(tempstr,[countytr'><td>]) IF NOT EMPTY(shiqu) daima=STREXTRACT(shiqu,"","<") shiqu=STREXTRACT(shiqu,"<td>") mingcheng=STREXTRACT(shiqu,"","<") INSERT INTO tqhdm VALUE(3,daima,"",mingcheng,"") ENDIF *****************市辖区代码结束*********** tempstr=STREXTRACT(tempstr,[href=']) IF EMPTY(tempstr) func2(test.responsetext) ELSE func1(tempstr,website) ENDIF ENDFUNC *!* 下载HTML代码程序块结束************************************** *!* 分析有链接的网页代码程序块即1、县区市2、街道办事处和乡镇******************************* FUNCTION func1(tempstr,website) LOCAL tempstr,website,websites,daima, mingcheng cc=cc+1 DO WHILE .T. websites=STREXTRACT(tempstr,"","'>") websites=LEFT(website,RATC('/',website))+websites tempstr=STREXTRACT(tempstr,"'>") daima=STREXTRACT(tempstr,"","<") tempstr=STREXTRACT(tempstr,"'>") mingcheng=STREXTRACT(tempstr,"","<") tempstr=STREXTRACT(tempstr,[href=']) INSERT INTO tqhdm VALUE(cc,daima,"",mingcheng,websites) IF EMPTY(tempstr) EXIT ENDIF ENDDO SELECT 网址 FROM tqhdm WHERE 层次=cc INTO CURSOR tmp SCAN for NOT EMPTY(网址) xiazai(网址) ENDSCAN ENDFUNC *!* 分析有链接的网页代码程序块结束******************************* *!* 分析无链接的网页代码程序块即居委会和村******************************* FUNCTION func2(tempstr) LOCAL tempstr,daima, mingcheng,daima4,cc5 cc5=cc+1 DO WHILE .T. tempstr=STREXTRACT(tempstr,[villagetr'><td>]) IF EMPTY(tempstr) EXIT ENDIF daima=STREXTRACT(tempstr,"","<") tempstr=STREXTRACT(tempstr,"<td>") daima4=STREXTRACT(tempstr,"","<") tempstr=STREXTRACT(tempstr,"<td>") mingcheng=STREXTRACT(tempstr,"","<") INSERT INTO tqhdm VALUE(cc5,daima,daima4,mingcheng,"") ENDDO ENDFUNC *!* 分析无链接的网页代码程序块结束*******************************
[ 本帖最后由 月沐庭轩 于 2012-10-28 16:06 编辑 ]
坚持学习vfp,QQ:306805680