#include <IE.au3>
Local $sURL = "http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E6%B7%B1%E5%9C%B3&searchArrivalAirport=%E5%8C%97%E4%BA%AC&searchDepartureTime=2012-02-14&searchArrivalTime=2012-02-17&nextNDays=0&startSearch=true&from=fi_ont_search"
Local $File = 'test.txt'
Local $str = _GetJsHTML($sURL, 'CLEAR: both')
If Not @error Then
FileDelete($File)
FileWrite($File, $str)
ShellExecute($File)
Else
MsgBox(48, '错误', '超时')
EndIf
Func _GetJsHTML($sURL, $sKey, $Wait = 5)
;afan提示: $sKey 最好为包含字符串的唯一特征字符
; $Wait 超时参数,单位秒
Local $ts = TimerInit()
Local $hGui = GUICreate('')
Local $oIE = _IECreateEmbedded(), $sHtm = '', $Flag, $Error, $GUIActiveX
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0)
$oIE.navigate($sURL)
_IELoadWait($oIE) ;注:这里的等待加载完毕并不准确
While TimerDiff($ts) / 1000 < $Wait
$sHtm = _IEDocReadHTML($oIE)
If StringInStr($sHtm, $sKey) Then
$Flag = 1
ExitLoop
EndIf
Sleep(10)
WEnd
If Not $Flag Then
$sHtm = ''
$Error = 1
EndIf
$oIE = 0
GUIDelete($hGui)
Return SetError($Error, 0, $sHtm)
EndFunc ;==>_GetJsHTML
|