acam Posted April 1, 2021 Share Posted April 1, 2021 (edited) Dear Master, I'm newbie in Autoit. I want to make bot capture and send webpage url (Firefox) and send to my telegram Group with BOT, But when i try to capture Webpage ( Elasticsearch ) its still loading but AUTOIT Start Capture, How to put waiting time before loading has finished? This is code: expandcollapse popup#Include <IE.au3> #Include <WinAPI.au3> #Include <ScreenCapture.au3> #Include <WindowsConstants.au3> #Include "../src/AutoItObject.au3" #include "../src/Telegram.au3" #include "../src/FF.au3" #include <Array.au3> ;Deklarasi Nama File Local $ChatID = '<My ID Chat>' ;Your ChatID here (take this from @MyTelegramID_bot) Local $Token = '<TOKENBOT>' ;Token here Local $fileName1 = "media/APM ELK - CMS.png" Local $fileName2 = "media/Discover ELK.png" ;Cek File sudah ada atau belum If FileExists($fileName1) then ;Jika sudah ada, maka akan dihapus FileDelete($fileName1) EndIf ;Cek File sudah ada atau belum If FileExists($fileName2) then ;Jika sudah ada, maka akan dihapus FileDelete($fileName2) EndIf ;Cek ID dan Token telegram bot If(($ChatID = '') or ($Token = '')) Then ConsoleWrite("Warning! ChatID or Token not specified!") Exit -1 EndIf _AutoItObject_StartUp() OnAutoItExitRegister('OnExit') WebCaptureTest("http://af-kubeelkprd01:5601/app/apm#/services", $fileName1) ElementCaptureTest("http://af-kubeelkprd01:5601/app/kibana#/discover", $fileName2) Func OnExit() _AutoItObject_Shutdown() EndFunc Func WebCaptureTest($Url, $ImageName) WinWait("","",30000) Local $hBmp = WebCapture($Url, 1366) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1366 Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 800, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 800) _IENavigate($oIE, $Url) Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func WebCapture($Url, $WebWidth = 1366) Local Const $DVASPECT_CONTENT = 1 Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}") Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 800, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 800) _IENavigate($oIE, $url) Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2) If @Error Then Return SetError(1, 0, 0) Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject($hMemDc, $hBmp) Local $sRECT = DllStructCreate($tagRECT) DllStructSetData($sRECT, "Top", 0) DllStructSetData($sRECT, "Left", 0) DllStructSetData($sRECT, "Right", $Width) DllStructSetData($sRECT, "Bottom", $Height) $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) Return $hBmp EndFunc Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}") Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);" Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender) Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDc, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False) If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID) If Not IsObj($Obj) Then Return SetError(1, 0, 0) Local $pObj = _AutoItObject_IDispatchToPtr($Obj) If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0) Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown) Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0) If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0) Local $pInterface = $aCall[2] Return _AutoItObject_WrapperCreate($pInterface, $Tag) EndFunc If FileExists($fileName1) then ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Test Kirim SS Dari URL") & @CRLF) EndIf Edited April 1, 2021 by Melba23 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 1, 2021 Moderators Share Posted April 1, 2021 Moved to the appropriate forum. Moderation Team acam 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
acam Posted April 1, 2021 Author Share Posted April 1, 2021 Dear Melba23, Can you give me Correct Link Forum? Thankyou Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 1, 2021 Moderators Share Posted April 1, 2021 acam, You are already in the correct forum. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
acam Posted April 1, 2021 Author Share Posted April 1, 2021 Thank you So Much Melba23. Sorry for my mistakes.... Link to comment Share on other sites More sharing options...
Danp2 Posted April 1, 2021 Share Posted April 1, 2021 Hi @acam, Since you said you're an AutoIt newbie, I'm assuming that this is code written by someone else that you want to modify. Is that correct? Dan P acam 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
acam Posted April 1, 2021 Author Share Posted April 1, 2021 Hi @Danp2, Correct, I copy from this forum... Link to comment Share on other sites More sharing options...
Danp2 Posted April 1, 2021 Share Posted April 1, 2021 Ok... Glancing at the script, it appears to use IE. Switching to FF could be a pretty big task. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
acam Posted April 1, 2021 Author Share Posted April 1, 2021 I have try to using FF by change oIE to oFF, but it make an error. I have try to open FF with Run("Firefox.exe", $urlToOpen ) But i can't make a capture page... Link to comment Share on other sites More sharing options...
Danp2 Posted April 1, 2021 Share Posted April 1, 2021 Like I said, it's a pretty big task to switch from IE to another browser. Have you considered sticking with IE? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
acam Posted April 1, 2021 Author Share Posted April 1, 2021 Spoiler Link to comment Share on other sites More sharing options...
Nine Posted April 1, 2021 Share Posted April 1, 2021 (edited) Try this quick & dirty fix. Add this line Sleep(20*1000) after _IENavigate($oIE, $url). You need to do this at 2 places. If that solves your immediate problem, we can think of a better solution later. Edited April 1, 2021 by Nine Danp2 and acam 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted April 1, 2021 Share Posted April 1, 2021 After looking at the code more closely, I realized that it was kind of old code. So I couldn't resist to "refresh" it with a more recent coding approach. I may have solve at the same time your loading problem. So there you go : expandcollapse popup#include <IE.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", True) Local $ChatID = '<My ID Chat>' ;Your ChatID here (take this from @MyTelegramID_bot) Local $Token = '<TOKENBOT>' ;Token here Local $fileName1 = "media/APM ELK - CMS.png" Local $fileName2 = "media/Discover ELK.png" If FileExists($fileName1) Then FileDelete($fileName1) If FileExists($fileName2) Then FileDelete($fileName2) If $ChatID = '' Or $Token = '' Then Exit MsgBox($MB_SYSTEMMODAL, "Warning", "ChatID or Token not specified!") WebCaptureTest("https://www.google.ca", $fileName1) ElementCaptureTest("https://www.google.ca", $fileName2) Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc ;==>WebCaptureTest Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1200 Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -1, -1) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) GUIDelete($hGUI) EndFunc ;==>ElementCaptureTest Func WebCapture($Url, $WebWidth = 1200) Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -5000, -5000) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height GUISetState() Local $hBmp = Capture_Window($hGUI, 0, 0, $Width, $Height) GUIDelete($hGUI) Return $hBmp EndFunc ;==>WebCapture Func Capture_Window($hWnd, $l, $t, $r, $b) Local $hDC_Capture = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $r, $b) Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap) _WinAPI_PrintWindow($hWnd, $hMemDC) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Return $hHBitmap EndFunc ;==>Capture_Window Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = ObjCreateInterface($oElement, "{3050F669-98B5-11CF-BB82-00AA00BDCE0B}", "DrawToDC hresult(hwnd);") Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDC, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc ;==>ElementCapture IDK, but I'm not even sure you need Func ElementCapture anymore. Let me know how it goes... acam 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
acam Posted April 2, 2021 Author Share Posted April 2, 2021 Hi @Nine, Thanks for Help me, You have solved my issue about Complete loading IE before capture with your code sleep(40*1000) ;20 second is not enough for my apps But my bot cannot send that picture to our group. expandcollapse popup#include <IE.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #Include "../src/AutoItObject.au3" #include "../src/Telegram.au3" #include <Array.au3> Opt("MustDeclareVars", True) Local $ChatID = '<CHAT-ID>' ;Your ChatID here (take this from @MyTelegramID_bot) Local $Token = '<BOT-TOKEN>' ;Token here Local $fileName1 = "media/APM ELK - CMS.png" Local $fileName2 = "media/Discover ELK.png" If FileExists($fileName1) Then FileDelete($fileName1) If FileExists($fileName2) Then FileDelete($fileName2) If(($ChatID = '') or ($Token = '')) Then ConsoleWrite("Warning! ChatID or Token not specified!") Exit -1 EndIf WebCaptureTest("<my_link>", $fileName1) ElementCaptureTest("<my_link2>", $fileName2) Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc ;==>WebCaptureTest Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1200 Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -1, -1) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Sleep(40*1000) ; added by Lord Nine Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) GUIDelete($hGUI) EndFunc ;==>ElementCaptureTest Func WebCapture($Url, $WebWidth = 1200) Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -5000, -5000) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Sleep(40*1000) ; added by Lord Nine Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height GUISetState() Local $hBmp = Capture_Window($hGUI, 0, 0, $Width, $Height) GUIDelete($hGUI) Return $hBmp EndFunc ;==>WebCapture Func Capture_Window($hWnd, $l, $t, $r, $b) Local $hDC_Capture = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $r, $b) Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap) _WinAPI_PrintWindow($hWnd, $hMemDC) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Return $hHBitmap EndFunc ;==>Capture_Window Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = ObjCreateInterface($oElement, "{3050F669-98B5-11CF-BB82-00AA00BDCE0B}", "DrawToDC hresult(hwnd);") Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDC, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc ;==>ElementCapture ;i want to send result capture to Bot telegram after finish capture ;but its still failed If FileExists($fileName1) then ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Test Kirim SS Dari URL") & @CRLF) EndIf And this error result Link to comment Share on other sites More sharing options...
Nine Posted April 2, 2021 Share Posted April 2, 2021 (edited) Well the photo has been taken correctly since you got the consolewrite stating that the file exists. Now it seems that the _SendPhoto function is not working properly. I am not familiar with Telegram Bot, but don't you need to _InitBot first ? Edited April 2, 2021 by Nine acam 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
acam Posted April 2, 2021 Author Share Posted April 2, 2021 OMG, i'm forget to initiate my bot first... Thanks for reminder it @Nine ConsoleWrite("! Initializing bot... " & _InitBot($Token) & @CRLF & @CRLF) I put this code after header... Link to comment Share on other sites More sharing options...
acam Posted April 2, 2021 Author Share Posted April 2, 2021 This is Full Code: expandcollapse popup#Include <IE.au3> #Include <WinAPI.au3> #Include <ScreenCapture.au3> #Include <WindowsConstants.au3> #Include "../src/AutoItObject.au3" #include "../src/Telegram.au3" #include "../src/FF.au3" #include <Array.au3> ;Deklarasi Nama File Local $ChatID = '<CHAT-ID>' ;Your ChatID here (take this from @MyTelegramID_bot) Local $Token = '<TOKEN-BOT>' ;Token here Local $fileName1 = "<First NameFile>" Local $fileName2 = "<Second Filename>" ;ConsoleWrite("Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit)." & @CRLF & _ ; "This file need a valid ChatID of a Telegram user who has already sent at least a message to the bot, and a valid token given by @BotFather." & @CRLF & _ ; "Insert this data in the source code." & @CRLF & @CRLF) ConsoleWrite("! Initializing bot... " & _InitBot($Token) & @CRLF & @CRLF) ;Cek ID dan Token telegram bot If(($ChatID = '') or ($Token = '')) Then ConsoleWrite("Warning! ChatID or Token not specified!") Exit -1 EndIf ;comments-start ;Cek File sudah ada atau belum If FileExists($fileName1) then ;Jika sudah ada, maka akan dihapus FileDelete($fileName1) EndIf ;Cek File sudah ada atau belum If FileExists($fileName2) then ;Jika sudah ada, maka akan dihapus FileDelete($fileName2) EndIf _AutoItObject_StartUp() OnAutoItExitRegister('OnExit') WebCaptureTest("<First Link>", $fileName1) ElementCaptureTest("<Second Link>", $fileName2) Func OnExit() _AutoItObject_Shutdown() EndFunc Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url, 1600) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1600 Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 900, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 900) _IENavigate($oIE, $Url) Sleep(40000) ; added by Lord Nine Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func WebCapture($Url, $WebWidth = 1600) Local Const $DVASPECT_CONTENT = 1 Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}") Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 900, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 900) _IENavigate($oIE, $url) Sleep(40000) ; added by Lord Nine Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2) If @Error Then Return SetError(1, 0, 0) Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject($hMemDc, $hBmp) Local $sRECT = DllStructCreate($tagRECT) DllStructSetData($sRECT, "Top", 0) DllStructSetData($sRECT, "Left", 0) DllStructSetData($sRECT, "Right", $Width) DllStructSetData($sRECT, "Bottom", $Height) $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) Return $hBmp EndFunc Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}") Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);" Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender) Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDc, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False) If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID) If Not IsObj($Obj) Then Return SetError(1, 0, 0) Local $pObj = _AutoItObject_IDispatchToPtr($Obj) If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0) Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown) Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0) If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0) Local $pInterface = $aCall[2] Return _AutoItObject_WrapperCreate($pInterface, $Tag) EndFunc ;comments-end If FileExists($fileName1) then ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Name To Show") & @CRLF) EndIf If FileExists($fileName2) then ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName2,"<Name To Show>") & @CRLF) EndIf But i have 1 issue more, My App Monitoring don't support IE... I dont know what i've to do. any idea? Link to comment Share on other sites More sharing options...
Danp2 Posted April 2, 2021 Share Posted April 2, 2021 14 minutes ago, acam said: My App Monitoring don't support IE No idea what this means. Please elaborate. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted April 2, 2021 Share Posted April 2, 2021 (edited) Are the links you have refer directly to images (.jpg or .png, or whatever) ? I ask because it is photos that you send thru Telegram. Anyway, could you explain what is it you are trying to achieve ? What is the end goal of your script ? Edited April 2, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
acam Posted April 3, 2021 Author Share Posted April 3, 2021 Spoiler Hi @Danp2, I've 2 monitoring apps. first Elasticsearch. It's support wiih IE, so i can get webpage screen capture like first image. But my second app monitoring don't support it like second image. Hi @Nine No, its url webpage. I just want to capture page from url, save to be image and send to telegram with bot. But 1 of my monitoring apps its not support IE... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now