找回密码
 加入
搜索
查看: 3539|回复: 5

[AU3基础] (已解决)对于已经打开的网页如何进行激活并获取该源文件另存为txt

[复制链接]
发表于 2011-5-1 02:44:41 | 显示全部楼层 |阅读模式
本帖最后由 xiezhang6263 于 2011-5-1 16:47 编辑
#include <ie.au3>
 $oHTTP = _IECreate("http://www.baidu.com/home.html", 1, 1, 1, 0)
$HTMLSource = _IEDocReadHTML($oHTTP)
MsgBox(0, "test:", $HTMLSource)
用该方法只能是重新打开网页,我想要的是对
已经打开的网页进行激活并获取该源文件另存为D:\源文件.txt。
我试着用
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("form", 300, 700)
$Button1 =GUICtrlCreateButton("源文件[F1]", 32, 180, 80, 40, 0)
HotKeySet("{F1}","yuanwenj")
GUISetState(@SW_SHOW); 显示对话框窗口
GUISetState()
While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
                        Exit
                Case $msg=$Button1
                        yuanwenj()
    EndSelect
WEnd
Func yuanwenj()
WinActivate("关于百度")
Sleep(200)
MouseClick("right",10,309,1,1)
Sleep(200)
send("v")
WinWaitActive("[CLASS:Notepad]")
Send("!f")
Sleep(200)
Send("a")
WinWaitActive("另存为","",3)
Sleep(400)
ClipPut("源文件") 
Sleep(400)
Send("{enter}")
EndFunc
但感觉模仿键盘鼠标操作的效果不是很好,有时会误操作不知道还有没有更好的办法。
 楼主| 发表于 2011-5-1 14:12:18 | 显示全部楼层
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("form", 300, 700)
$Button1 =GUICtrlCreateButton("源文件[F1]", 32, 180, 80, 40, 0)
$chuangkou = ("百度一下") ;窗口目标
$lcw = ("另存为")
HotKeySet("{F1}","yuanwenj")
GUISetState(@SW_SHOW); 显示对话框窗口
GUISetState()
While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
                        Exit
                Case $msg=$Button1
                        yuanwenj()
    EndSelect
WEnd
Func yuanwenj()
Opt("MouseCoordMode", 2);激活窗口客户区的相对坐标
        WinActivate($chuangkou);最多等待3秒,3秒后不管如何,脚本继续
If WinActive($chuangkou) Then
        Sleep(200)
        MouseClick("right",125,630,1,1)
        Sleep(200)
        send("v")
        WinWaitActive("[CLASS:Notepad]","", 3)
If WinActive("[CLASS:Notepad]") Then
        Sleep(400)
        Send("!f")
        Sleep(400)
        Send("a")
EndIf
        WinWaitActive($lcw,"",3)
If WinActive($lcw) Then        
        Sleep(400)
        ControlSetText($lcw, "", "[CLASS:Edit; INSTANCE:1]", "源文件",1)  ;保存的txt名称
        ControlClick($lcw,"","[CLASS:Combox; INSTANCE:3]","left",2)  ;选择txt格式
        ControlClick($lcw,"","[CLASS:Button; INSTANCE:2]","left",1) ;点击确定按钮
        ControlClick($lcw,"","[CLASS:Button; INSTANCE:1]","left",1) ;是否替换选择是
        Send("!{f4}")
EndIf
Else
        MsgBox(4096,"错误", "请登录", 5)
EndIf
Sleep(400)
EndFunc
这段是我完善了部分的代码,不过还是没办法。
MouseClick("right",10,309,1,1)有时会点击在网页的图片上就没办法了。
发表于 2011-5-1 15:35:19 | 显示全部楼层
低级办法

#include <ie.au3>
;Run(@ProgramFilesDir & '\Internet Explorer\IEXPLORE.EXE http://www.baidu.com')
;Sleep(3000)
$oHTTP = _IEAttach('百度一下');要确认IE窗口存在,否则下面要做容错处理.
$HTMLSource = _IEDocReadHTML($oHTTP)
MsgBox(0, "test:", $HTMLSource)
 楼主| 发表于 2011-5-1 16:46:44 | 显示全部楼层
回复 3# ceoguang
_IEAttach这个以前不懂,谢谢ceoguang 。学习了。

附加到指定的 Internet Explorer 实例,基于您所选择的模式按照字符串/子字符串匹配.
#include <IE.au3>
_IEAttach ( $s_string [, $s_mode = "Title" [, $i_instance = 1]] )
 楼主| 发表于 2011-5-1 17:24:18 | 显示全部楼层
本帖最后由 xiezhang6263 于 2011-5-1 17:28 编辑

回复 3# ceoguang
#include <ie.au3>
#include <array.au3>
;Run(@ProgramFilesDir & '\Internet Explorer\IEXPLORE.EXE [url]http://www.baidu.com[/url]')
;Sleep(3000)
$oHTTP = _IEAttach("戴尔");要确认IE窗口存在,否则下面要做容错处理.
$HTMLSource = _IEDocReadHTML($oHTTP)
$str=StringRegExp($HTMLSource,'\<A.*\>(.*?)(?=\<\/A\>)',3) 
 _ArrayDisplay($str)
得到的结果为什么与下面得到的结果不同
#include <array.au3>
#include <INet.au3>
$urlsource=_INetGetSource ( "http://www.it-hztc.com/product.asp?tid=452" )
If Not @error Then
        $str=StringRegExp($urlsource,'\<A.*\>(.*?)(?=\<\/A\>)',3)   
        _ArrayDisplay($str)
EndIf
 楼主| 发表于 2011-5-1 17:27:37 | 显示全部楼层
_IEDocReadHTML本函数返回的源代码是经过客户端改动之后的网页的源码(如通过AutoIt或者客户端JavaScript). 因此可能和在浏览器中显示的或通过_INetGetSource得到的源码不一样.怎么样能实现相同的呢?不知道是不是
_IEDocReadHTML问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 06:41 , Processed in 0.079655 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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