#include <IE.au3>
#include <WinAPI.au3>
Global $mykey,$keywords,$start,$n,$end,$element,$oForm,$oQuery1,$nurl,$key
_IEErrorHandlerRegister()
Global $oIE = _IECreateEmbedded()
GUICreate("mytest", 700, 600, (@DesktopWidth - 700) / 2, (@DesktopHeight - 600) / 2)
GUICtrlCreateObj($oIE, 0, 0, 700, 600)
AutoItSetOption("TrayIconHide", 1)
GUISetState(@SW_SHOW)
$keywords=iniread(@ScriptDir& "" &"ie.ini", "关键词", "keywords", "Notfound")
$key=StringSplit($keywords,",",2)
For $mykey In $key
If @error = -1 Then ExitLoop
$start = iniread(@ScriptDir& "" &"ie.ini", "开始序号", "start", "Notfound")
$end = iniread(@ScriptDir& "" &"ie.ini", "结束序号", "end", "Notfound")
If $start=$end Then $end=$end+1
$n=$end-$start
Dim $i=0
For $i=0 To $n
If $start=$end Then ExitLoop
$element=$start
$url = "http://www.baidu.com"
_IENavigate($oIE, $url)
_IELoadWait($oIE)
$oForm = _IEFormGetObjByName($oIE, "f")
$oQuery1 = _IEFormElementGetObjByName($oForm, "wd")
Sleep("2000")
_IEFormElementSetValue($oQuery1, $mykey)
Send("{ENTER}")
;就是这里,使用传送键盘enter,submit,鼠标点击都会在某些电脑上出问题。。。。高手指点一下
;_IEFormSubmit($oForm,1)
;MsgBox(0,"",@Error)
_replace()
_IELinkClickByIndex($oIE, $element)
$start=$start+1
Next
Next
Sleep("6000")
WinClose("mytest")
Do
$nurl = _IEPropertyGet($oIE, "locationurl")
If $nurl <> $url Then
_replace()
$url = $nurl
EndIf
Until GUIGetMsg() = -3
Func _replace()
Local $body, $string
_IELoadWait($oIE)
$body = _IEBodyReadHTML($oIE)
$string = StringRegExpReplace($body, '\btarget=_blank', 'target=_self')
$string = StringRegExpReplace($string, '\btarget="_blank"', 'target=_self')
_IEBodyWriteHTML($oIE, $string)
EndFunc ;==>_replace