找回密码
 加入
搜索
查看: 1917|回复: 3

[IE类操作] 求助!程序无法循环

[复制链接]
发表于 2011-3-24 13:51:30 | 显示全部楼层 |阅读模式
为了能够批量的从网上查询一些东西,我写了下面的代码,但是只能运行一次,之后不知道怎么回事就停住了,希望各位大侠帮忙看看,谢谢了!
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <date.au3>
#include <INet.au3>
#Include <Misc.au3>
#include <Debug.au3>
#include <sqlite.au3>
#include <date.au3>
#include <SQLite.dll.au3>
#include <Array.au3>
;--------------------------------------------------------------------------------------
$sFilePath1 = @ScriptDir & "\USPart.xls" ;把文件路径赋给$sFilePath1
$oExcel = _ExcelBookOpen($sFilePath1)    ;打开$sFilePath1
$uspair = "http://portal.uspto.gov/external/portal/pair"

If @error = 1 Then
    MsgBox(0, "错误!", "无法创建对象!")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "错误!", "文件不存在!")
    Exit
EndIf

Dim $x=1,$x1=0,$US_IE
Dim $msg;定义EXCEL中单元格的位置
Const $y = 1;
Dim $reader;定义变量记录EXCEL中数据
Do
        
Dim $CExcel=_ExcelReadCell($oExcel,$x,$y+1)
;MsgBox(0,"00",$CExcel)
Until($CExcel<>"1")

;Dim $pageCount
        

CreateEmbededIE()

Do
        
        While _IELoadWait($US_IE) <>1
                MsgBox(0,"00","在循环等待")
        Sleep(400)
WEnd
MsgBox(0,"00","这是第"&$x&"次显示")
        Do
        Do 
                ;Sleep(400)
                $msg=CNumber()
                MsgBox(0,"循环","第一个验证码"&$msg)
        Until($msg<>"验证码")
        If $reader = "" Then
        $reader =_ExcelReadCell($oExcel,$x,$y);
        EndIf
;$pageCount = _ExcelReadCell($oExcel,$x+5,$y)
Do
        Do
        Do 
                ;Sleep(400)
                $msg=CNumber()
                MsgBox(0,"循环","第二个验证码"&$msg)
                Until($msg<>"验证码")
While _IELoadWait($US_IE) <>1
        Sleep(400)
WEnd
;MsgBox(0,"输出",$reader)
CRaido()
WNumber()
CButton()
;MsgBox(0,"输出",$reader)
While _IELoadWait($US_IE) <>1
        Sleep(400)
WEnd
Dim $CImge=SImage()
While _IELoadWait($US_IE) <>1
        Sleep(400)
WEnd
;MsgBox(0, "00",$CImge)
Until($CImge=-1) ;检查图片是否被点上
Dim $CSfileAndDfile=SfileAndDfile()
Until($CSfileAndDfile=-1)
;MsgBox(0,"00","1")
Dim $check=Dfile()
;MsgBox(0,"00",$check)
Until($check=1)
_ExcelWriteCell($oExcel,"1",$x,$y+1)
SNewCase()
;While _IELoadWait($US_IE) <>1
;            Sleep(1000)
;        WEnd
        $x=$x+1
        $reader = _ExcelReadCell($oExcel,$x,$y)
        MsgBox(0,"$reader",$reader)
Until($reader="")
MsgBox(0,"00","0")
While 1
        WEnd

;--------------------------------------------------------------------------------------------------
Func CNumber()
        While _IELoadWait($US_IE) <>1
            Sleep(1000)
        WEnd
                Return USPageWho()
                
        EndFunc
        
;--------------------------------------------------------------------------------------------------
Func CreateEmbededIE()
        ;Local $uspair = "http://portal.uspto.gov/external/portal/pair"
        Local $wt="USDownload"
        If $CmdLine[0]>0 Then 
                $wt= $wt & $CmdLine[1]
                ;_DebugSetup("USHIEB_" & $CmdLine[1] );& " " & ShortTime())
        Else
                ;_DebugSetup("USHIEB " & ShortTime())
                ;Exit                
        EndIf
        GUICreate($wt,800, 600, (@DesktopWidth - 640) / 4, (@DesktopHeight - 580) / 4, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_VISIBLE);+ $WS_CLIPCHILDREN); 
        GUISetOnEvent($GUI_EVENT_CLOSE,"OnAutoitExit")
        ;If $CmdLine[0]>0 Then GUISetState(@SW_HIDE)
        $US_IE = _IECreateEmbedded()
        $GUIActiveX0= GUICtrlCreateObj($US_IE, 0, 0, 800, 600)
        GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
        If $CmdLine[0]>0 Then WinActivate("USDownload")
        _IENavigate($US_IE,$uspair)        
EndFunc

;--------------------------------------------------------------------------------------------------

Func OnAutoItExit()
        ;If $US_IE<>0 Then _IEQuit($US_IE)
        Exit
EndFunc   ;==>OnAutoItExit

;--------------------------------------------------------------------------------------------------

Func CButton()
        Dim $form = _IEFormGetObjByName($US_IE,"save")
        Dim $button =_IEFormElementGetObjByName($form,"SubmitPair")
        _IEAction($button,"click");
EndFunc
;--------------------------------------------------------------------------------------------------
Func WNumber()
        Dim $form = _IEFormGetObjByName($US_IE,"save")
        Dim $Txt =_IEFormElementGetObjByName($form,"dosnum")
        _IEFormElementSetValue($Txt,$reader)
EndFunc
;--------------------------------------------------------------------------------------------------
Func CRaido()
        Dim $form = _IEFormGetObjByName($US_IE,"save")
        Dim $click =_IEFormElementGetObjByName($form,"appSelectedType",4)
        _IEAction($click,"click")
EndFunc
;--------------------------------------------------------------------------------------------------
Func SImage()
        _IEImgClick($US_IE,"Image File Wrapper", "alt")
        While _IELoadWait($US_IE) <>1
        Sleep(200)
    WEnd
        Return _IEImgClick($US_IE,"sort by Page Count","alt");点击图片排序
        ;Dim $form = _IEFormElementGetObjByName($US_IE,"MainPage")
        ;Dim $click = _IEFormElementGetObjByName($form,"imag3")
        ;_IEAction($Image,"click")
EndFunc

;--------------------------------------------------------------------------------------------------
Func SfileAndDfile()
        Const $KWord="Non-Final Rejection"
        $oTable=_IEGetObjById($US_IE,"ifwinnertable")
        $aTableData =_IETableWriteToArray ($oTable, True)
        $aIndex=_ArraySearch($aTableData,$KWord,0,0,0,1,1)
        ;MsgBox(0,"找到了","位于数组中第"& $aIndex &"个索引中")
        ;While _IELoadWait($US_IE) <>1
        ;Sleep(500)
    ;WEnd
        Dim $form = _IEFormGetObjByName($US_IE,"downloadForm")
        Dim $click =_IEGetObjById($form,"cb"&$aIndex-1)
        
        _IEAction($click,"click")
    ;_ArrayDisplay($aTableData)
        Return _IEImgClick($US_IE,"Download the selected documents as PDF","alt",0,0)
EndFunc

;--------------------------------------------------------------------------------------------------
Func Dfile()
        ;MsgBox(0,"00","2")


        Sleep(3000)
        ;WinSetTitle("文件下载","","YY")
        WinWait("文件下载","",10)
        WinActivate("[last]")
        ;WinWait("[last]","",10)
        ;MsgBox(0,"00","3")
    ;WinActivate("[last]")
        ControlClick("[last]","","[CLASS:Button; TEXT:保存(&S);]")
        Sleep(1000)
        ControlClick("[last]","","[CLASS:Button; TEXT:保存(&S);]")
        WinWait("另存为")
        ;MsgBox(0,"文件名",$reader)
        ControlSend("[last]","","[CLASS:Edit; INSTANCE:1]",$reader)
        ControlClick("[last]","","[CLASS:Button; TEXT:保存(&S);]")
        WinSetTitle("已完成 0%,共 ShowPdfBook (来自 portal.uspto.gov)","","YY")
        Dim $a=WinGetHandle("YY")
        MsgBox(0,"00",$a)
        Dim $b=WinWaitClose($a)
        ;MsgBox(0,"00",$b)
        Return $b
        EndFunc
        ;Sleep(2000)
        ;MsgBox(0,"文件名","正等着呢")
        ;If WinExists()
        ;Dim $WHandle=WinGetHandle("[CLASS:#32770; INSTANCE:0]","已完成")
        ;If $DWindows=-1 Then
        ;MsgBox(0,"没取到",$DWindows) 
    ;Else 
        ;MsgBox(0,"取到啦",$DWindows)
        ;EndIf
        ;Dim $form = _IEFormGetObjByName($US_IE,"downloadForm")
        ;Dim $click =_IEFormElementGetObjByName($form,"Examiner's search strategy and results",0)
        ;_IEAction($click,"click")

;--------------------------------------------------------------------------------------------------
Func SNewCase()
        _IEImgClick($US_IE,"Select New Case","alt",0,0)
        MsgBox(0,"00","点完图片了")
        EndFunc
;--------------------------------------------------------------------------------------------------
Func USPageWho()
        if _IEPropertyGet($US_IE, "readystate") <> 4 Then Return "3"
        Local $txt = ""
        $txt = _IEBodyReadText($US_IE)
        Select
                Case StringInStr($txt,"that is not yet available for public inspection.")
                        Return "不可用"
                Case StringInStr($txt, "Transaction Description")
                        Return "历史"
                Case StringInStr($txt, "Available Documents")
                        Return "文件"
                Case StringInStr($txt, "Internal Server Error")
                        Return "内部错误"
                Case StringInStr($txt, "Current Status, Planned Events, Descriptions, Operating Requirements/ Compatibilities and Standard Hours of Availability for Online Business Systems ")
                        Return "内部维护" ;系统维护
                Case StringInStr($txt, "verification code")
                        Return "验证码"
                Case StringInStr($txt, "high system volume")
                        Return "检索超负荷"
                case StringInStr($txt, "Please re-enter")
                        Return "检索失败"
                Case StringInStr($txt, "Search for Application")
                        Return "检索" ;非超负荷、非失败的检索页
                Case StringInStr($txt, "Bibliographic Data")
                        Return "信息-著录项目"
                Case StringInStr($txt, "Patent Application Information Retrieval")
                        Return "信息" ;非检索页、非著录项目页的信息页
                Case Else
                        Return "未知"
        EndSelect
EndFunc   ;==>USPageWho
发表于 2011-3-24 14:58:02 | 显示全部楼层
谁告诉你do可以嵌套了
 楼主| 发表于 2011-3-24 15:08:11 | 显示全部楼层
那请问要如何解决呢?
发表于 2011-3-24 15:16:25 | 显示全部楼层
格式整理好了再说,看不清楚
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-9 04:52 , Processed in 0.080356 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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