#include <IE.au3>
#include <File.au3>
#include <Array.au3>
Opt('MustDeclareVars', 1)
Global $sUrl = 'http://picsee.net/', $sTempFile, $oIE, $oForm, $oInput, $iPID, $sMessage, _
$sFilePic = @MyDocumentsDir & '\Скриншоты\Captured Image9.png', $oTDs, $oInputs, $iCount
Dim $aResult[6][2] = [[5],['BBCode с миникартинкой:'],['BBCode без миникартинки:'],['HTML с миникартинкой:'], _
['HTML без миникартинки:'],['Прямой URL картинки']]
$sMessage = _Check_Pic($sFilePic)
If @error Then
MsgBox(16, 'Error', $sMessage)
Exit
EndIf
OnAutoItExitRegister('_Del')
$sTempFile = _TempFile(@TempDir)
$iPID = _Set_Pic($sFilePic)
If Not $iPID Then
MsgBox(16, 'Error', 'Error')
Exit
EndIf
$oIE = _IECreate($sUrl);, 0, 0)
If @error Then Exit
For $i = 1 To 1
$oForm = _IEFormGetCollection($oIE, 0)
If @error Then ExitLoop
$oInput = _IEFormElementGetObjByName($oForm, 'file[]')
If @error Then ExitLoop
_IEAction($oInput, 'click')
If @error Then ExitLoop
_IELoadWait($oIE)
If @error Then ExitLoop
_IEFormSubmit($oForm)
If @error Then ExitLoop
_IELoadWait($oIE)
If @error Then ExitLoop
$oTDs = _IETagNameGetCollection($oIE, 'td')
If @error Then ExitLoop
For $oTD In $oTDs
For $j = 1 To $aResult[0][0]
If StringInStr($oTD.innertext, $aResult[$j][0]) Then
$oInputs = _IETagNameGetCollection($oTD, 'input')
If @error Then ContinueLoop
For $oInput In $oInputs
If $oInput.type == 'text' Then
$aResult[$j][1] = $oInput.value
$iCount += 1
ExitLoop
EndIf
Next
EndIf
Next
If $iCount = 5 Then ExitLoop
Next
Next
If @error Then
_IEQuit($oIE)
MsgBox(16, 'Error', 'Error')
Else
_IEQuit($oIE)
_ArrayDisplay($aResult)
EndIf
Func _Check_Pic($s_FilePic)
Local $sExtension, $sString = 'jpeg|jpg|gif|png|'
If Not FileExists($s_FilePic) Then Return SetError(1, '', 'Файл отсутствует')
If FileGetSize($s_FilePic) >= 5 * 1024 * 1024 Then Return SetError(1, '', 'Файл слишком большой')
$sExtension = StringRegExpReplace($s_FilePic, '^.*\.', '')
If Not StringInStr($sString, $sExtension) Then Return SetError(1, '', 'Формат не поддерживается')
Return SetError(0)
EndFunc ;==>_Check_Pic
Func _Del()
If ProcessExists($iPID) Then
ProcessClose($iPID)
Sleep(500)
EndIf
FileDelete($sTempFile)
EndFunc ;==>_Del
Func _Set_Pic($s_File_Pic)
Local $h_File, $i_Pid
Local $s_Script = "#NoTrayIcon" & @CRLF & _
"$hWin = WinWait('[Title:Выбор файла для выгрузки; Class:#32770]', '', 60)" & @CRLF & _
"If Not $hWin Then" & @CRLF & _
"ToolTip('Ошибка 1', 0, 0)" & @CRLF & _
"Sleep(5000)" & @CRLF & _
"Exit" & @CRLF & _
"EndIf" & @CRLF & _
"ControlSetText($hWin, '', '[CLASS:Edit; INSTANCE:1]', '" & $s_File_Pic & "')" & @CRLF & _
"Sleep(500)" & @CRLF & _
"If ControlGetText($hWin, '', '[CLASS:Edit; INSTANCE:1]') <> '" & $s_File_Pic & "' Then" & @CRLF & _
"ToolTip('Ошибка 2', 0, 0)" & @CRLF & _
"Sleep(5000)" & @CRLF & _
"Exit" & @CRLF & _
"EndIf" & @CRLF & _
"ControlClick($hWin, '', '[CLASS:Button; INSTANCE:2]')" & @CRLF & _
"Sleep(500)" & @CRLF & _
"If WinExists($hWin) Then" & @CRLF & _
"ToolTip('Ошибка 3', 0, 0)" & @CRLF & _
"Sleep(5000)" & @CRLF & _
"EndIf" & @CRLF & _
"Exit"
$h_File = FileOpen($sTempFile, 2)
FileWrite($h_File, $s_Script)
FileClose($h_File)
$i_Pid = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sTempFile & '"')
Return $i_Pid
EndFunc ;==>_Set_Pic