找回密码
 加入
搜索
查看: 11524|回复: 21

[IE类操作] 遍历?循环?问题求助!

 火.. [复制链接]
发表于 2010-4-10 07:15:30 | 显示全部楼层 |阅读模式
近日在练习AU3的IE操作,现在有这样一个问题

如何利用AU3获取
http://www.google.com/dirhp
中的所有分类名称

首页大类、单独子页,很容易实现
就是如何让程序来遍历整个目录树(哎,实在是算法的知识欠缺)

我的代码,见2楼。

请教,谢谢!
 楼主| 发表于 2010-4-10 07:15:41 | 显示全部楼层
#include <IE.au3>
#include <INet.au3>
#include <file.au3>


#Region public var

; 文件夹
Global Const $gc_floder_ini = @ScriptDir & "\ini" ; ini 的文件夹

; 网址
Global Const $gc_url_google = 'http://www.google.com' ; google
Global Const $gc_url_google_dir = $gc_url_google & '/dirhp' ; google directory


;文件名
Global Const $gc_name_index = "Index" ; Index
Global Const $gc_ini_index = $gc_floder_ini & '\' & $gc_name_index & '.ini'

Global Const $gc_name_myDate = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR ;2009-09-11 03


#EndRegion public var
_check_Initial()




;获取单独下级分类
$sUrl = 'http://www.google.com/Top/Arts/'
_test($sUrl)
Func _test($sUrl)

        ;$sUrl = $gc_url_google & $sUrl
        
        $sText = _INetGetSource($sUrl)        ;获取源代码
        
        ;正则数组
        $regex_sub = '<a href="([^"]+)">(?:<b>)?([^<]+)(?:</b>)?</a> <font color=#6f6f6f size=-1>\(\d+\)</font>'
        $aDirs = StringRegExp($sText,$regex_sub,3)
        
        ;检查错误
        If @error Then
                MsgBox(0,'Wrong','regex error')
        Else
                ;获取大类名称
                $sMailDirName = StringRegExp($sUrl,'http://www\.google\.com/Top/([^/]+)/',3)
                $sMailDirName = $sMailDirName[0] 
                ConsoleWrite('$sMailDirName:' & $sMailDirName & @CRLF)
                
                $sUrl_parent = StringReplace($sUrl,'http://www.google.com','')
                
                ;<== 获取大类名称
                
                ; ini 
                $ini_subdir = $gc_floder_ini & '\' & $sMailDirName & '.ini'
                
                ;loop dir
                For $iDir=0 To UBound($aDirs) / 2 -1
                        $sUrl_sub = $aDirs[2 * $iDir]
                        $sName_sub = $aDirs[2 * $iDir + 1]
                        
                        ;格式化链接
                        If Not StringInStr($sUrl_sub,'/Top/') Then
                                $sUrl_sub = $sUrl_parent & $sUrl_sub
                        EndIf
                        ;write to ini
                        IniWrite($ini_subdir,$sMailDirName,$sName_sub,$sUrl_sub)
                        
                Next ;<== loop dir
                
        EndIf;<== 检查错误
        
        

        
EndFunc




;首页大类
Func _index()
        
        $sText = _INetGetSource($gc_url_google_dir)
        ;ConsoleWrite($sText & @CRLF)
        
        
        
        
        $aDirs = StringRegExp($sText,'href="/Top/([^/]+)/">',3)
        
        If @error Then
                MsgBox(0,'Wrong','regex error')
        Else
                
                ;loop dir
                For $iDir=0 To UBound($aDirs)-1
                        $sDir = $aDirs[$iDir]
                        
                        If $sDir<>'World' Then
                                IniWrite($gc_ini_index,$gc_name_index,$sDir,'/Top/' & $sDir & '/')
                        EndIf
                        
                Next ;<== loop dir
                
        EndIf
        
        
EndFunc





Func _check_Initial()
        ;检测 site 文件夹是否存在
        If Not FileExists($gc_floder_ini) Then ; ini path
                DirCreate($gc_floder_ini)
        EndIf

EndFunc   ;==>_check_Initial
发表于 2010-4-10 14:51:22 | 显示全部楼层
循环“ 获取匹配的链接源码 从源码中匹配链接 ”应该不是很难,今天很多事,不能帮忙,LZ先自己琢磨下吧……
 楼主| 发表于 2010-4-10 19:24:42 | 显示全部楼层
多谢版主afan的关注
这个问题我琢磨了两三天了,一直不得其解,不得已才发贴的
谢谢

我的问题主要在如何写那块遍历的代码?
知道链接,用正则表达式来获取内容,这个我应该没问题
发表于 2010-4-11 12:44:31 | 显示全部楼层
LZ获取的是英文类别?我觉得还是弄中文比较好,直观些~
 楼主| 发表于 2010-4-11 14:57:26 | 显示全部楼层
中文、英文无所谓,主要是算法
发表于 2010-4-11 16:41:40 | 显示全部楼层
本帖最后由 afan 于 2010-4-11 16:47 编辑

唉~ 1个大类几百项就快遍历完了,蹦出个

很抱歉...
...您的计算机或网络可能正在发送自动查询。为了保护我们的用户,我们目前无法处理您的请求。


14个大类差不多有几千上万项,玩不下去。撤退。
发表于 2010-4-11 16:48:05 | 显示全部楼层
不懂,帮顶。。。。
发表于 2010-4-11 16:51:53 | 显示全部楼层
不懂,帮顶。。。。
Hen5ei 发表于 2010-4-11 16:48



    懂也没啥用,除非出现以上字符后自动更换Ip再继续…… 不过怎么说都意义不大了
 楼主| 发表于 2010-4-11 19:33:09 | 显示全部楼层
麻烦版大,能否告诉如何实现的,关键是实现的算法,谢谢
 楼主| 发表于 2010-4-12 10:39:56 | 显示全部楼层
唉~ 1个大类几百项就快遍历完了,蹦出个


afan版主,请问您是如何遍历的,能否告知,谢谢
发表于 2010-4-12 10:48:37 | 显示全部楼层
不太明白,DOMDocument可否变向解决楼主问题。
发表于 2010-4-12 12:17:24 | 显示全部楼层
回复 11# 老榆头

这个需要隐藏,免得……

游客,如果您要查看本帖隐藏内容请回复
发表于 2010-4-12 12:34:47 | 显示全部楼层
看看afan的代码。。。
 楼主| 发表于 2010-4-12 14:10:44 | 显示全部楼层
多谢,afan:
已复制下来,还没有仔细看
多谢

现在有些急事,稍晚一些再仔细看看
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 03:46 , Processed in 0.086292 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表