找回密码
 加入
搜索
楼主: ac5474012

求助如何获取一段网页中的文字

[复制链接]
 楼主| 发表于 2009-9-30 01:15:41 | 显示全部楼层
终于把 刷新页面的搞定了
#include <IE.au3>
#include <Constants.au3>
$file = FileOpen("zi.txt", 0)
If $file = -1 Then
        MsgBox(0, "错误", "在脚本目录下建立zi.txt的文本文件在写几个汉字")
        Exit
EndIf
$xh = 1
$p = 0
While 1

        Select
                Case $p = 0
                        $chars = FileRead($file, 2)
                        If @error = -1 Then ExitLoop
                        $oIE = _IECreate("http://www.uname.cn/html/dic/4/63_9084.shtml")
                        $a = _IEGetObjByName($oIE, "Query")
                        _IEFormElementSetValue($a, $chars);账号
                        $oSubmit = _IEGetObjByName($oIE, "Query")
                        WinWaitActive("在线字典")
                        _IEAction($oSubmit, "focus")
                        Send("{enter}")
                        _IEQuit($oIE)
                        WinWait("", "完毕")
                        If Not WinActive("", "完毕") Then WinActivate("", "完毕")
                        Sleep(2000)
                        WinWaitActive("", "完毕")
                        Sleep(1000)
                        $ckp = WinExists("http://www.uname.cn/searchcenter.asp - Microsoft Internet Explorer", "完毕")
                        Select
                                Case $ckp = 0
                                        WinWait("在线字典", "完毕")
                                        If Not WinActive("在线字典", "完毕") Then WinActivate("在线字典", "完毕")
                                        Sleep(2000)
                                        WinWaitActive("在线字典", "完毕")
                                        $var = ControlGetText("在线字典", "", "Edit1")
                                        WinClose("在线字典", "完毕")
                                        ProcessClose("IEXPLORE.EXE")
                                        $oIE2 = _XmlHttp($var)
                                        $sR = StringRegExp($oIE2, '#FFFFFF">(.*?)( )?</td>', 3)
                                        If @error = 0 Then
                                                IniWrite("a2.ini", "Section3", $chars, $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9])
                                        EndIf
                                        $xh = $xh + 1
                                        TrayTip("状态." & $p & ".已经完成了第" & $xh & "个字上一个是" & $chars, $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9], 10)
                                Case $ckp = 1
                                        ProcessClose("IEXPLORE.EXE")
                                        $p = 1
                                Case Else
                                        MsgBox(0, "", "所有条件都不成立!")
                        EndSelect
                Case $p = 1
                        TrayTip("状态." & $p & ".已经完成了第" & $xh & "个字上一个是" & $chars, $sR[0] & "," & $sR[2] & "," & $sR[3] & "," & $sR[4] & "," & $sR[6] & "," & $sR[7] & "," & $sR[8] & "," & $sR[9], 10)
                        Sleep(100000)
                        $p = 0
                Case Else
                        MsgBox(0, "", "所有条件都不成立!")
        EndSelect



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

评分

参与人数 1金钱 +5 贡献 +3 收起 理由
afan + 5 + 3

查看全部评分

 楼主| 发表于 2009-9-30 09:59:54 | 显示全部楼层
哎呀 今天起来一看还是会被卡住啊~ 现在正在看在那里被卡主。
 楼主| 发表于 2009-9-30 10:09:32 | 显示全部楼层
现在关键是如何获取这个字的地址。我打算把这个分两步进行。
发表于 2009-9-30 12:04:58 | 显示全部楼层
17# ac5474012


是不是刷新受限了?那样的话可试试更改IP或使用代理是否有效

评分

参与人数 1金钱 +2 收起 理由
ac5474012 + 2 在帮我看看这个吧~ 嘻嘻

查看全部评分

 楼主| 发表于 2009-10-2 09:48:46 | 显示全部楼层
19# afan

应该不是,不过我打算换一种获取的方法
http://www.uname.cn/dic/zidian.asp在这里输入新文字,这样网页不会打开一个新网页。但是你知道当网页跳转后如何控制它吗?


跳转后

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-10-2 16:38:42 | 显示全部楼层
终于全部解决了,跳过过度刷新限制!但是还有个问题! 在别的计算机上会报这个错误。还要解决这个啊~ 怎么弄得


全部代码
#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)
        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", "")
        $a = _IEGetObjByName($oIE, "gb")
        _IEFormElementSetValue($a, $chars)
        $oSubmit = _IEGetObjByName($oIE, "gb")
        $b = _IEGetObjByName($oIE, "Submit")
        _IEAction($b, "click")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN&" 步骤3", "")
        _IELoadWait($oIE)
        $oLinks = _IELinkGetCollection($oIE)
        $i = 0
        For $oLink In $oLinks
                $i = $i + 1
                If $i = 75 Then
                        $s = $oLink.href
                        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN&" 步骤4", $s)
                EndIf
        Next
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN&" 步骤5", $s)
        $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-2 16:42:50 | 显示全部楼层
或者报 请求动作失败(请求于对象)
 楼主| 发表于 2009-10-2 16:56:59 | 显示全部楼层
本帖最后由 ac5474012 于 2009-10-2 16:59 编辑

第一次可以,但循环到第二次就卡在这句话
$oIE = _IECreate("http://www.uname.cn/dic/zidian.asp", 0, 0)
报上面的错误为什么呢?
 楼主| 发表于 2009-10-2 17:17:52 | 显示全部楼层
真奇怪我的计算机就没问题呢?
 楼主| 发表于 2009-10-2 23:38:36 | 显示全部楼层
#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)
        $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", "")
        $a = _IEGetObjByName($oIE, "gb")
        IniWrite("e1cw.ini", $chars, @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & " 步骤2.1", "")
        _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
出现这个问题

E:\au3\autoit3.3.0.0.1\Include\IE.au3 (2709) : ==> ??????(?????).:
If IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)) Then
If IsObj($o_object.document^ ERROR
 楼主| 发表于 2009-10-2 23:53:35 | 显示全部楼层
$o_object.visible = $f_visible
$o_object.visible = $f_visible^ ERROR

line - 1:

Error:请求动作失败(请求于对象)
 楼主| 发表于 2009-10-3 00:11:28 | 显示全部楼层
每次都停在
$a = _IEGetObjByName($oIE, "gb") 
而且报ie.au3的错误,这怎么解决呢?
If IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)) Then
If IsObj($o_object.document^ ERROR
 楼主| 发表于 2009-10-3 10:47:14 | 显示全部楼层
我有次试了一下,这个和我的速度有关系?
如果这样第二次就报错误了
#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", 0, 0)
        $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)
        _IEQuit($oIE)
WEnd
但是如果这样的话就能长久25次多吧,但是如何才能稳定呢?
#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)
        Sleep(1000)
        $oIE = _IECreate("http://www.uname.cn/dic/zidian.asp", 0, 0)
        Sleep(1000)
        $a = _IEGetObjByName($oIE, "gb")
        Sleep(1000)
        _IEFormElementSetValue($a, $chars)
        Sleep(1000)
        $oSubmit = _IEGetObjByName($oIE, "gb")
        Sleep(1000)
        $b = _IEGetObjByName($oIE, "Submit")
        Sleep(1000)
        _IEAction($b, "click")
        Sleep(1000)
        _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)
        _IEQuit($oIE)
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 06:58 , Processed in 0.076684 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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