找回密码
 加入
搜索
查看: 2953|回复: 14

除了利用ie.au3还有什么其他方法控制ie达到我这个脚本的要求?

[复制链接]
发表于 2009-10-3 00:50:31 | 显示全部楼层 |阅读模式
我不知道为什么这个经常报ie.au3的错误,比如
E:\au3\3.3.1.1-2\Include\IE.au3 (244) : ==> ??????(?????).:
$o_object.visible = $f_visible
$o_object.visible = $f_visible^ ERROR
有时2次循环有时30多次。很不稳定我都不知道怎么解决。所以我想问问还有没有其他方法能满足我的要求???
#include <IE.au3>
#include <Constants.au3>
#include <Date.au3>

$file = FileOpen("zi.txt", 0)
If $file = -1 Then
        MsgBox(0, "错误", "在脚本目录下建立zi.txt的文本文件在写几个汉字")
        Exit
EndIf
$sl = 0
While 1
        Assign("oIE", "0", 2)
        Assign("a", "0", 2)
        
        $chars = FileRead($file, 2)
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤1", "")
        $oIE = _IECreate("http://www.uname.cn/dic/zidian.asp", 0, 0)
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2", "")
        Sleep(1000)
        $a = _IEGetObjByName($oIE, "gb")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2.1", @Error)
        _IEFormElementSetValue($a, $chars)
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2.2", "")
        $oSubmit = _IEGetObjByName($oIE, "gb")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2.3", "")
        $b = _IEGetObjByName($oIE, "Submit")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2.4", "")
        _IEAction($b, "click")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤3", "")
        _IELoadWait($oIE)
        $sHTML = _IEBodyReadHTML($oIE)
        $Link = StringRegExp($sHTML, 'href="(/html/dic/[^"]+)">', 3)
        If @error = 0 Then
                $s = 'http://www.uname.cn' & $Link[0]
        Else
                IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤5-这将是个错误回馈,而且也会因此停止程序的运行", $s)
        EndIf
        $oIE2 = _XmlHttp($s)
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤6", $s)
        $sR = StringRegExp($oIE2, '#FFFFFF">(.*?)( )?</td>', 3)
        If @error = 0 Then
                IniWrite("e1.ini", "Section3", @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & "_" & $chars, $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9])
        ElseIf @error <> 0 Then
                IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤7", $chars & "," & $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9])
        EndIf
        $sl = $sl + 1
        ToolTip($sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9], 50, 50, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & @CR & "已经完成了第" & $sl & "个字上一个是" & $chars, 0, 4)
        _IEQuit($oIE)
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤8", "关闭")
WEnd

Func _XmlHttp($Url) ;Sanhen
        Local $oHTTP, $sReturn
        $oHTTP = ObjCreate("microsoft.xmlhttp")
        $oHTTP.Open("get", $Url, False)
        $oHTTP.Send()
        $sReturn = BinaryToString($oHTTP.responseBody)
        Return $sReturn
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤9", "会不会使这里的问题?")
EndFunc   ;==>_XmlHttp
发表于 2009-10-3 07:03:35 | 显示全部楼层
嗯 曾几何时 我也时不时出现过几次这样的错误 无解

不过控制ie  用ie.au3是最 专业 方便 的解决方案

评分

参与人数 1金钱 +1 收起 理由
ac5474012 + 1 加了延时会有好转,但是

查看全部评分

 楼主| 发表于 2009-10-3 08:32:08 | 显示全部楼层
那可怎么解决啊,我这个几乎30个就会出错。出错率太高了
发表于 2009-10-3 10:26:02 | 显示全部楼层
_IEAction($b, "click")

        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤3", "")

        _IELoadWait($oIE)

        $sHTML = _IEBodyReadHTML($oIE)


这样写肯定会出错  超时没有处理好哦
发表于 2009-10-3 10:29:37 | 显示全部楼层
If _IELoadWait ( $oIE ,100,8000) = 1 Then ;这里来处理超时,8秒
     $Log = _IEBodyReadHTML($oIE)  
Else
    $Log = "1"
EndIf

当$Log = "1"  网页超时错误 后面自己处理哦

评分

参与人数 1金钱 +3 收起 理由
ac5474012 + 3 十分感谢,不过能在来看看我的回复吗?

查看全部评分

发表于 2009-10-3 10:37:13 | 显示全部楼层
楼主是要用该网页的搜索功能吧  建议使用POST 提交 那样又快又稳定。。
 楼主| 发表于 2009-10-3 11:55:48 | 显示全部楼层
是在感谢,不过通过实验我发现一般都是在步骤一和步骤二后面失败。而这个
 IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤3", "")
就是因为失败了才后写上去,作为检测使用。我又测试发现
我有次试了一下,这个和我的速度有关系?
如果这样第二次就报错误了#include
$file = FileOpen("zi.txt", 0)
If $file = -1 Then
        MsgBox(0, "错误", "在脚本目录下建立zi.txt的文本文件在写几个汉字")
        Exit
...
ac5474012 发表于 2009-10-3 10:47


而现在我看了你的回复发现有可能和快速关闭和打开有关。所以我现在正在测试这个我去掉了关闭网页,并且依附打开。现在已经测试到了45个字。还在继续测试。请你看看我这样测试对吗?
#include <IE.au3>

$file = FileOpen("zi.txt", 0)
If $file = -1 Then
        MsgBox(0, "错误", "在脚本目录下建立zi.txt的文本文件在写几个汉字")
        Exit
EndIf
$sl = 0
While 1
        $chars = FileRead($file, 2)
        $oIE = _IECreate("http://www.uname.cn/dic/zidian.asp", 1, 0,1,1)
        $a = _IEGetObjByName($oIE, "gb")
        _IEFormElementSetValue($a, $chars)
        $oSubmit = _IEGetObjByName($oIE, "gb")
        $b = _IEGetObjByName($oIE, "Submit")
        _IEAction($b, "click")
        _IELoadWait($oIE)
        $sHTML = _IEBodyReadHTML($oIE)
        $Link = StringRegExp($sHTML, 'href="(/html/dic/[^"]+)">', 3)
        If @error = 0 Then
                $s = 'http://www.uname.cn' & $Link[0]
        Else
                MsgBox(0,"","错误")
        EndIf
        IniWrite("e1.ini", "Section3",$chars, $s)
        $sl = $sl + 1
        ToolTip("网址: " & $s, 50, 50, "已经完成了第" & $sl & "个字上一个是" & $chars, 0, 4)
WEnd
 楼主| 发表于 2009-10-3 12:15:39 | 显示全部楼层
但是我每取一个网址au3就报一个这个错误?不过不影响。我已经取得了190个没有间断了。
IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch
发表于 2009-10-3 17:19:10 | 显示全部楼层
IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch

这个错误是 _IEAttac 函数出错了。有肯能没有点击到。
 楼主| 发表于 2009-10-4 12:27:16 | 显示全部楼层
这是我最新的代码,已经算稳定了,但是第一次测试在1300个字时出错误,错误还是一样,而第二次是在第4个字时出错误。请大家帮我看看可能是哪里不对?
#include <IE.au3>
#include <Constants.au3>
#include <Date.au3>

$file = FileOpen("zi.txt", 0)
If $file = -1 Then
        MsgBox(0, "错误", "在脚本目录下建立zi.txt的文本文件在写几个汉字")
        Exit
EndIf
$sl = 0
While 1
        $chars = FileRead($file, 2)
        $oIE = _IECreate("http://www.uname.cn/dic/zidian.asp", 1, 0,1,1)
        Sleep(1000)
        $a = _IEGetObjByName($oIE, "gb")
        _IEFormElementSetValue($a, $chars)
        $oSubmit = _IEGetObjByName($oIE, "gb")
        $b = _IEGetObjByName($oIE, "Submit")
        _IEAction($b, "click")
        _IELoadWait($oIE)
        $sHTML = _IEBodyReadHTML($oIE)
        $Link = StringRegExp($sHTML, 'href="(/html/dic/[^"]+)">', 3)
        If @error = 0 Then
                $s = 'http://www.uname.cn' & $Link[0]
        Else
                IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤5-这将是个错误回馈,而且也会因此停止程序的运行", $s)
        EndIf
        $oIE2 = _XmlHttp($s)
        $sR = StringRegExp($oIE2, '#FFFFFF">(.*?)( )?</td>', 3)
        If @error = 0 Then
                IniWrite("e1.ini", "Section3", @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & "_" & $chars, $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9])
        ElseIf @error <> 0 Then
                IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤7", $chars & "," & $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9])
        EndIf
        $sl = $sl + 1
        ToolTip($sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9], 50, 50, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & @CR & "已经完成了第" & $sl & "个字上一个是" & $chars, 0, 4)
WEnd

Func _XmlHttp($Url) ;Sanhen
        Local $oHTTP, $sReturn
        $oHTTP = ObjCreate("microsoft.xmlhttp")
        $oHTTP.Open("get", $Url, False)
        $oHTTP.Send()
        $sReturn = BinaryToString($oHTTP.responseBody)
        Return $sReturn
EndFunc   ;==>_XmlHttp
发表于 2009-10-5 12:48:31 | 显示全部楼层
把你程序中 点击模拟点击网页的代码 换成

Func _Post($Word)
            $oHTTP = ObjCreate("Microsoft.xmlhttp")
            $oHTTP.Open("Post","http://www.uname.cn/dic/ShowWord.asp",false)
            $oHTTP.setRequestHeader("Cache-Control", "no-cache")
            $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")  
            $oHTTP.setRequestHeader("Referer","http://www.uname.cn/dic/wordlist.asp")
            $oHTTP.Send("collection=gb&gb="&$Word&"&Submit=+%BC%EC+%CB%F7+")
        $sReturn = BinaryToString($oHTTP.responseBody)
                FileWrite("Log.TXT",$sReturn)
        Return $sReturn
EndFunc

这是一个POST 提交 $WORD 为你搜索的关键字,返回搜索后的网页代码

评分

参与人数 1金钱 +3 收起 理由
ac5474012 + 3 啊 多谢,我试试看。

查看全部评分

 楼主| 发表于 2009-10-8 19:26:55 | 显示全部楼层
11# rho123


我试验了,不过说 您输入的汉字不存在! 这是为什么?是不是不能输入中文?

这是返回代码
[section2]
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<link href='/images/main.css' rel='stylesheet' type='text/css'></head>
<table width='530' border='0' align='center' cellpadding='0' cellspacing='0' class='font_1'>
<tr><td height='80'></td></tr></table>
<table width='530' height='315'  border='0' align='center' cellpadding='0' cellspacing='0' class='font_1'>
<tr><td align='center' valign='middle' background='/images/bg_err_top.gif' height='97'></td></tr><tr><td background='/images/bg_err_mid.gif'>
<table width='85%'  border='0' cellpadding='0' cellspacing='0' class='font_1' align='center' style='word-break:break-all;Width:fixed'>
<tr><td height='28' align='center' valign='middle' ><img src='/images/warnning.gif' width='200' height='64'></td></tr>
<tr><td height='28' align='left' valign='middle' background='/images/bg_line.gif'><b>产生错误的原因:</b></td></tr>
<tr><td height='50' valign='middle' class='tdb'><br><li>您输入的汉字不存在!请重新输入!</li></td></tr>
<tr><td height='6' align='right' valign='top' > </td></tr>
<tr><td height='28' align='center' valign='middle' background='/images/bg_line.gif'> </td></tr>
<tr><td height='28' align='center' valign='middle' background='/images/bg_line.gif'><a href='javascript:history.go(-1)'><< 返回上一页</a>  <a href='javascript:window.close();'><< 关闭窗口</a></td></tr>
<tr><td height='28' align='right' valign='middle' > </td></tr>
</table></td></tr>
<tr><td background='/images/bg_err_bot.gif' height='42'></td></tr>
</table>
发表于 2009-10-8 19:49:03 | 显示全部楼层
先将汉字编码GB2312
发表于 2009-10-8 19:59:22 | 显示全部楼层
对哦 直接提交肯定不行 中文要转换
 楼主| 发表于 2009-10-18 11:28:26 | 显示全部楼层
论坛里面好像有一个转换中文的例子,我怎么找不到了?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-26 01:58 , Processed in 0.080356 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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